First, we look at the n=1 shell (the first shell). It has:
An s-orbital holds 2 electrons. Thus n=1 shell can hold two electrons.
The n=2 (second) shell has:
s-orbitals can hold 2 electrons, the p-orbitals can hold 6 electrons. Thus, the second shell can have 8 electrons.
The n=3 (third) shell has:
s-orbitals can hold 2 electrons, p-orbitals can hold 6, and d-orbitals can hold 10, for a total of 18 electrons.
Therefore, the formula 2n22n2 holds!