* Magnesium has 2 valence electrons (electrons in its outermost shell). It wants to lose these electrons to achieve a stable octet (8 electrons) in its outer shell.
* Nitrogen has 5 valence electrons. It wants to gain 3 electrons to achieve a stable octet.
When magnesium and nitrogen react, magnesium will lose its two valence electrons, becoming a positively charged ion (Mg²⁺). Nitrogen will gain three electrons from three magnesium atoms, becoming a negatively charged ion (N³⁻).
These oppositely charged ions attract each other electrostatically, forming an ionic bond. The resulting compound will be magnesium nitride (Mg₃N₂).