Sodium has one valence electron and holds it loosely; chlorine has seven and pulls hard for an eighth. Put them together and the electron moves: sodium becomes Na+ (11 protons, 10 electrons) and chlorine becomes Cl− (17 protons, 18 electrons). Opposite charges attract, and that electrostatic attraction is the ionic bond. Both ions now have full outer shells, matching the noble gases neon and argon.
The attraction does not stop at one partner. Each Na+ pulls on every nearby Cl−, so the ions stack into a cube-shaped lattice in which each ion touches six of the opposite kind. A single grain of salt is one lattice of about 1018 ions. The formula NaCl gives only the 1 : 1 ratio, called a formula unit; there is no separate NaCl molecule. The charges must cancel, so Mg2+ with Cl− gives MgCl2, and Al3+ with O2− gives Al2O3.
Dissolving is not a sign of a weak bond. Salt dissolves because polar water molecules crowd around each ion and pull it out of the lattice, yet dry salt must be heated to 801 °C to melt. And not every compound of two elements is ionic: two nonmetals, such as carbon and chlorine in CCl4, share electrons instead. A metal with a nonmetal, or an electronegativity difference above about 1.7, points to ionic bonding.
Think of it like this. An ionic crystal is like a stack of magnets arranged so that every north pole faces a south pole: each piece is gripped from all sides, so the stack is strong. Shift one layer sideways by a single place and north faces north everywhere, so the layers spring apart. That is why salt crystals shatter instead of bending. Unlike magnets, each ion carries one charge, not two poles.
Core idea. A metal transfers electrons to a nonmetal, and the resulting positive and negative ions attract each other in every direction, building a lattice whose charges cancel; that lattice explains the formula, hardness and high melting point of salts.