Basically, there are 18 because each shell is divided into s, p and d sub-shells. s always holds 2, p always holds 6 and d always holds 6 (there's an f shell that holds 14, it goes up in 4's xD)
Basically, shell 3, when full, looks like this:
1s2, 2s2, 2p6, 3s2, 3p6, 3d10
There are 2 on the 1st shell, 2+6=8 on the 2nd shell, and 2+6+10=18 on the 3rd shell