Ionic bonding is the electrostatic attraction between oppositely charged ions. It typically forms between a metal and a nonmetal, that is, between an element with low ionization energy and an element with high electron affinity. When the difference in electronegativity between two atoms is large (conventionally greater than about 1.8 on the Pauling scale), electrons are transferred rather than shared. The metal atom loses one or more electrons to achieve a stable, usually noble-gas, electron configuration, becoming a positively charged cation. The nonmetal atom gains those electrons to complete its valence shell, becoming a negatively charged anion.
Consider sodium chloride. A sodium atom has the configuration $1s^2 2s^2 2p^6 3s^1$. By losing its single $3s$ electron it forms $\text{Na}^+$