* Magnesium (Mg) is a metal and tends to lose electrons to achieve a stable electron configuration. It has 2 valence electrons and wants to lose them to become a +2 ion (Mg²⁺).
* Oxygen (O) is a nonmetal and tends to gain electrons to achieve a stable electron configuration. It has 6 valence electrons and wants to gain 2 electrons to become a -2 ion (O²⁻).
In the ionic bond, magnesium will donate its two valence electrons to oxygen. This results in the formation of magnesium ions (Mg²⁺) and oxide ions (O²⁻). The opposite charges attract, forming the ionic compound magnesium oxide (MgO).