The pattern of maximum possible electrons = 2n^2 is correct.
Also, note that Brian's answer is good and takes a different approach.
Have you learned about quantum numbers yet?
If not...
Each shell (or energy level) has some number of subshells, which describe the types of atomic orbitals available to electrons in that subshell. For example, the s subshell of any energy level consists of spherical orbitals. The p subshell has dumbbell-shaped orbitals. The orbital shapes start to get weird after that. Each subshell contains a specified number of orbitals, and each orbital can hold two electrons. The types of subshells available to a shell and the number of orbitals in each subshell are mathematically defined by quantum numbers. Quantum numbers are parameters in the wave equation that describes each electron. The Pauli Exclusion Principle states that no two electrons in the same atom can have the exact same set of quantum numbers. A more thorough explanation using quantum numbers can be found below. However, the outcome is the following:
The subshells are as follows:
etc.
Each energy level (shell) has more subshells available to it:
The pattern is thus: 2,8,18,32,50,72,..... or 2n^2
In practice, no known atoms have electrons in the g or h subshells, but the quantum mechanical model predicts their existence.
Using quantum numbers to explain why the shells have the subshells they do and why the subshells have the number of orbitals they do.
Electrons in atoms are defined by 4 quantum numbers. The Pauli Exclusion Principle means that no two electrons can share the same quantum numbers.
The quantum numbers:
For the first shell, n=1, so only one value of ℓ is allowed: ℓ=0, which is the s subshell. For ℓ=0 only mℓ=0 is allowed. Thus the s subshell has only 1 orbital. The first shell has 1 subshell, which has 1 orbital with 2 electrons total.
For the second shell, n=2, so the allowed values of ℓ are: ℓ=0, which is the ss subshell, and ℓ=1, which is the ppsubshell. For ℓ=1, mℓ has three possible values: mℓ=−1,0,+1. Thus the p subshell has three orbitals. The second shell has 2 subshells: the ss subshel, which has 1 orbital with 2 electrons, and the p subshell, which has 3 orbitals with 6 electrons, for a total of 4 orbitals and 8 electrons.
For the third shell, n=3, so the allowed values of ℓ are: ℓ=0, which is the s subshell,ℓ=1, which is the p subshell, and ℓ=2, which is the d subshell. For ℓ=2, mℓ has five possible values: mℓ=−2,−1,0,+1,+2. Thus the d subshell has five orbitals. The third shell has 3 subshells: the s subshell, which has 1 orbital with 2 electrons, the p subshell, which has 3 orbitals with 6 electrons, and the d subshell, which has 5 orbitals with 10 electrons, for a total of 9 orbitals and 18 electrons.
For the fourth shell, n=4, so the allowed values of ℓ are: ℓ=0, which is the s subshell, ℓ=1, which is the p subshell, ℓ=2, which is the d subshell, and ℓ=3, which is the f subshell. For ℓ=3, mℓ has seven possible values: mℓ=−3,−2,−1,0,+1,+2,−3. Thus the f subshell has seven orbitals. The fourth shell has 4 subshells: the s subshell, which has 1 orbital with 2 electrons, the p subshell, which has 3 orbitals with 6 electrons, the d subshell, which has 5 orbitals with 10 electrons, and the f subshell, which has 7 orbitals with 14 electrons, for a total of 16 orbitals and 32 electrons.