* Magnesium (Mg) is a metal and tends to lose two electrons to achieve a stable electron configuration. This makes it a cation with a +2 charge (Mg²⁺).
* Chlorine (Cl) is a nonmetal and tends to gain one electron to achieve a stable electron configuration. This makes it an anion with a -1 charge (Cl⁻).
The electrostatic attraction between the positively charged magnesium ion (Mg²⁺) and the negatively charged chloride ions (Cl⁻) results in the formation of an ionic bond. The resulting compound is magnesium chloride (MgCl₂).