Ionic bonding occurs between metals and nonmetals due to their differences in electronegativity. Metals have relatively low ionization energies and lose electrons to form cations, while nonmetals have high electronegativity and gain electrons to form anions. Oppositely charged ions are then attracted through electrostatic forces to form an ionic compound.