The first shell, n=1 has only one sub- shell (s)
The second shell, n=2 has two sub- shells (s and p)
The third shell, n=3 has three sub- shells (s, p and d)
The fourth shell, n=4 has four sub- shells (s, p, d and f)
s sub- shell can hold a maximum of 2 electrons
p sub- shell can hold a maximum of 6 electrons
d sub- shell can hold a maximum of 10 electrons
dont know about f sub- shell, sorry
So, there is a basic rule which decides which sub- shell has the lowest energy level, the next sub- shell which then has the lowest, etc.
The 1s subshell always fills first. Now you have to decide which sub- shell will fill next. In order to decide this, you have to look firstly at the number in front of the sub- shell, the prinicpal quantum number- when this increases the energy level of the sub- shell also increases. So, 3s sub- shell has greater energy than the 2s sub- shell.
You then have to look the kind of the sub- shell. The s sub- shell always fills first, then the p, then the d, etc.
So for an element like sodium, atomic mass=11, its electron configuration would be-
- 1s2 2s2 2p6 3s1