The intent and purpose of the Second Amendment was to prevent the federal government from infringing upon the peoples right to keep and bear arms, as the militia was necessary for the security of those Free States. The reason why this amendment was adopted was so that the federal government couldn't subjugate the militia (i.e. able-bodied males 18-45 in each state) simply by neglecting to provide for them (see George Mason). Through the Militia Acts, the Founders, being big believers in the separation and balancing of powers, gave the ability to form, regulate, train and discipline the militia to the states, but gave the federal government the power to call them into service against or within each state, under narrowly defined conditions (insurrection, war, etc.) It was thought that by doing this, a standing army could be largely avoided, and neither the states nor the federal government would be able to overpower one another.
This ended definitively with the Civil War.