* Magnesium (Mg) is a metal and tends to lose two electrons to achieve a stable electron configuration. This creates a positively charged magnesium ion (Mg²⁺).
* Nitrogen (N) is a nonmetal and tends to gain three electrons to achieve a stable electron configuration. This creates a negatively charged nitrogen ion (N³⁻).
The strong electrostatic attraction between the positively charged magnesium ions and the negatively charged nitrogen ions forms the ionic bond, resulting in the compound magnesium nitride (Mg₃N₂).