* Magnesium is a metal and tends to lose two electrons to achieve a stable electron configuration.
* Nitrogen is a nonmetal and tends to gain three electrons to achieve a stable configuration.
To form a neutral compound, three magnesium atoms (each losing two electrons) will combine with two nitrogen atoms (each gaining three electrons). This results in the ionic compound Mg₃N₂ where the positive magnesium ions (Mg²⁺) are attracted to the negative nitrogen ions (N³⁻).