It seems such a simple formula, that each electron shell can hold in principle two times a square number. I imagine there must be a geometrical reason for this, that's to do with the way electron orbitals "fit" around the nucleus. If this is so, what is it?
A good insight!
The number of electrons in each orbital are double the odd numbers. The s orbital can hold 2, p holds 6, d holds 10 and f has 14: double 1, 3, 5 and 7. If you add the odd numbers, you get a square number:
1 = 1
1 + 3 = 4
1 + 3 + 5 = 9
1 + 3 + 5 + 7 = 16
The doubling is due to the Pauli exclusion principle; in each orbital, an electron of a specific energy can be in one of two spin states.
It is interesting to see spectral lines split in a magnetic field (Zeeman effect) or an electrostatic field (Stark effect): one line may become 3, 5 or 7 lines. It clearly shows how orbital theory was derived.