Magnesium nitride is composed of magnesium and nitrogen atoms. Magnesium is a metal and nitrogen is a nonmetal. When a metal and a nonmetal react, they form an ionic bond. In magnesium nitride, the magnesium atom loses two electrons to the nitrogen atom, resulting in a magnesium ion with a 2+ charge and a nitride ion with a 3- charge. These ions are then attracted to each other by their opposite charges, forming an ionic bond.