Magnesium, an essential element with atomic number 12, forms divalent cations (Mg2+) in ionic compounds. This divalent nature results from the loss of two valence electrons, leaving magnesium with a stable octet configuration. The formation of Mg2+ is driven by its relatively low electronegativity and high ionization energy, allowing it to easily transfer its valence electrons during ionic bonding.