* Magnesium is a metal and tends to lose two electrons to achieve a stable electron configuration.
* Chlorine is a nonmetal and tends to gain one electron to achieve a stable electron configuration.
When magnesium and chlorine react, magnesium loses two electrons, forming a positively charged magnesium ion (Mg²⁺). Each chlorine atom gains one electron, forming a negatively charged chloride ion (Cl⁻). The electrostatic attraction between these oppositely charged ions creates the ionic bond, resulting in the formation of magnesium chloride (MgCl₂).