The relative energy of sublevels is decided by (n+l) value of a given subshell . Lower the n+l value , lower is the energy. Lower energy subshells are filled first .
Second shell has two subshells ( s and p ) also termed as 2s and 2p subshell
for 2s subshell, n+l value is 2+0=2( l=0 for s subshell)
and for 2p subshell, n+l value is 2+1=3 ( l=1 for p subshell)
2s subshell will be filled first and 2p subshell will be filled, once 2s subshell is filled.
Third shell has three subshells ( s,p and d ) also termed as 3s,3p and 3d subshell
for 3s subshell, n+l value is 3+0=3 ( l=0 for s subshell)
for 3p subshell, n+l value is 3+1=4 ( l=1 for p subshell)
for 3d subshell, n+l value is 3+2=5 ( l=2 for d subshell)
3s subshell will be filled first and 3p subshell will be filled, once 3s subshell is filled and then 3d subshell.
If two subshells have same n+l value, the one with lower n , value will be filled first.
for 2p subshell, n+l value is 2+1=3 , and 3s subshell , n+l , value is 3+0=3, since 2p subshell has lower n value , so it will be first filled.