The Second Amendment to the U.S. Constitution states, "A well-regulated Militia, being necessary to the security of a free State, the right of the people to keep and bear Arms, shall not be infringed." There is much debate as to what this amendment means, due to its confusing wording.
Some people believe that the Second Amendment protects the rights of individual citizens to possess firearms, meaning that it would be unconstitutional for Congress to restrict this right in any way. However, there is also the states' rights theory, which suggests that this amendment merely restricts Congress from passing any laws that would limit a state's ability to defend itself, i.e. to have an armed militia.
In the case of United States v. Miller in 1939, the U.S. Supreme Court basically ruled that the amendment only applied to firearms that have "some reasonable relationship to the preservation or efficiency of a well-regulated militia...."
This ruling stood for nearly 70 years, until the Supreme Court reversed the decision in the case of The District of Columbia v. Heller. In this case, the Supreme Court ruled that the amendment protected an individual's rights to own firearms that are not connected to any military service. They also ruled that a firearm can be used for any lawful purpose, such as for use in self-defense in an individual's own home.