An ionic compound is a lattice of ions, not a set of molecules. How tightly is it held together? Coulomb's Law in Atoms and Sizes of Ions answer that with two numbers per ion: its charge and its size.
Key idea
The lattice energy is the energy needed to separate one mole of an ionic solid into gaseous ions, for example $$\mathrm{NaCl(s)} \to \mathrm{Na^+(g)} + \mathrm{Cl^-(g)} \qquad \Delta H = +787\ \text{kJ/mol}.$$ It grows with the ion charges and shrinks with the distance between ion centers: $$\text{lattice energy} \propto \frac{|q_1 q_2|}{r_1 + r_2}.$$ Charge matters most.
Why it works
Each ion in the crystal is surrounded by ions of the opposite charge, and the Coulomb energy of each pair goes as $q_1 q_2 / r$. Doubling both charges, as from $\mathrm{Na^+Cl^-}$ to $\mathrm{Mg^{2+}O^{2-}}$, multiplies the product $q_1q_2$ by 4. Changing sizes changes $r$ by maybe 10 to 30 percent. So a $2+/2-$ salt beats a $1+/1-$ salt almost no matter the sizes, and among salts with the same charges, smaller ions win. (Some books give lattice energy the opposite sign, as the energy released when the lattice forms. The size of the number is the same.)
Worked example: Rank by lattice energy
Rank KCl, NaCl and MgO by lattice energy.
- MgO has charges $2+$ and $2-$: $|q_1q_2| = 4$. The other two have $|q_1q_2| = 1$. MgO is far ahead.
- NaCl and KCl: same charges, but $\mathrm{Na^+}$ (102 pm) is smaller than $\mathrm{K^+}$ (138 pm), so NaCl's ions are closer.
Answer: KCl < NaCl < MgO (about 715, 787 and 3800 kJ/mol).
Worked example: Charge against size
Which has the larger lattice energy, $\mathrm{NaF}$ or $\mathrm{CaO}$? Ion radii: $\mathrm{Na^+}$ 102, $\mathrm{F^-}$ 133, $\mathrm{Ca^{2+}}$ 100, $\mathrm{O^{2-}}$ 140 pm.
- NaF: $\dfrac{1 \times 1}{102 + 133} = \dfrac{1}{235} = 0.00426$.
- CaO: $\dfrac{2 \times 2}{100 + 140} = \dfrac{4}{240} = 0.0167$.
- CaO's value is about 3.9 times NaF's.
Answer: CaO (about 3400 against 920 kJ/mol).
Common mistake
Ranking lattice energies by ion size alone. "$\mathrm{LiF}$ has the smallest ions, so it must beat $\mathrm{MgO}$" is wrong: MgO's charges multiply to 4, and no difference in size makes up for that. Check charges first; use sizes only to break ties between salts with the same charges.
Lattice energy shows up in properties you can see. MgO melts near 2800 °C, NaCl at 801 °C. A larger lattice energy also tends to make a salt less soluble in water, though hydration of the ions matters too.