Separate the formation of charged particles from the attraction that holds a lattice together, then explain radius trends and evidence for mobile ions.
Electron transfer forms ions; attraction forms the ionic bond
An atom that loses electrons becomes a cation; an atom that gains electrons becomes an anion. Magnesium loses its two outer 3s electrons to become Mg²⁺, while oxygen gains two electrons to complete 2p and becomes O²⁻. The nucleus does not change.
Ionic bonding is the strong electrostatic attraction between oppositely charged ions. Electron transfer explains how ions form, but is not the bond itself. In solid magnesium oxide, each ion attracts several oppositely charged neighbours throughout a giant lattice; there are no isolated MgO molecules.
