In the United States that is. In other places throughout the world, the military is not used for such noble purposes. As we have seen throughout history, outside of its proper sphere, the military can mean the very destruction of our liberties.
Just to point out an obvious example, Great Britain during the events that transpired before the Revolutionary War used their military to enforce their unjust policies on the colonies. Ultimately, these efforts were prevented when the colonists started to fight back.
It's as Noah Webster says,
“Before a standing army can rule, the people must be disarmed."
We as citizens must have the right to bear arms in order to protect ourselves from the abuse of our military. Now I know we would all like to believe that our government would never oppress us with the military, a driving idea of the Constitution and our early government is that we must prepare for the worst possible government.
By its nature, government is made up of fallible men. If men were perfect, we wouldn't need a government to ensure one man not harm another's rights to life, liberty, and property. Unfortunately, we cannot trust these same men to remain honorable in office.
Our system of government was created to provide set limits in order to check the power of these men. Indeed we are ordained to fight back, with force if need be, should the government overstep its bounds.
This is why we have the right to bear arms in the second amendment. It is not strictly speaking to protect ourselves against criminals although guns are great for that too. No, it is to allow us to protect ourselves against the potential abuse of our government.
But in this regard, we must not only have access to guns, but actually need access to the same guns the military has. This may be a scary prospect, but think about it. How are we to protect ourselves against the military if their firepower is significantly greater than those of the citizens?
Alexander Hamilton explains this idea in greater detail,
“If circumstances should at any time oblige the government to form an army of any magnitude, that army can never be formidable to the liberties of the people, while there is a large body of citizens, little if at all inferior to them in discipline and use of arms, who stand ready to defend their rights.”