a simple formula to find the maximum number of electrons with a given principal quantum number, n, is 2n^2.
in your case, n=3, so 2n^2 is 18 e-.
if you write out the values for the other quantum numbers for n=3, you get:
l= 0, 1, 2 (these correspond to the s, p, d subshells, respectively)
ml= 0
-1, 0, 1
-2, -1, 0, 1, 2
these ml values represent the number of orbitals you have, and there are two electrons that can occupy each orbital. so you have 9 total orbitals times 2 electrons each, and you have 18 total.