An ionic bond forms when electrons are lost by one atom and gained by another atom. In this process, one atom becomes a positively charged ion (cation) after losing electrons, while the other atom becomes a negatively charged ion (anion) after gaining those electrons. The electrostatic attraction between these oppositely charged ions creates the ionic bond.
In contrast, when electrons are shared equally by two or more atoms, a covalent bond is formed.