Metals lose electrons to form cations, while non-metals gain electrons to form anions. The electrostatic attraction between these oppositely charged ions results in the formation of an ionic bond.