Magnesium is a metal in Group 2A whose atom has two electrons in the outermost electron shell. Oxygen is a nonmetal in Group 6A whose atom has six electrons in the outermost electron shell. Two additional electrons are needed to complete the oxygen atom’s outermost electron shell. Thus, the magnesium atom will transfer its two electrons in its outermost shell to the oxygen atom. The magnesium atom becomes a positively charged ion (Mg^2+), and the oxygen atom becomes a negatively charged ion (O^2-). The electrostatic attraction between the positive and negative ions holds the atoms together in an ionic compound.