All the elements within a group have the same number of electrons in their outermost shell. Magnesium is in group 2 because a magnesium atom has 2 electrons in its outer shell/outermost energy level.
OR give answer in terms of Magnesium's electronic configuration: 2.2