How do electrons fill orbitals?
Energy of the subshell ( orbitals) is decided by n+ l rule. Orbitals with a lower n + ℓ value are filled before those with higher n + ℓ values. In this context, n represents the principal quantum number and ℓ the azimuthal quantum number; the values ℓ = 0, 1, 2, 3 correspond to the s, p, d, and f labels, respectively.
1s, n+ l = 1+0 = 1,2s, n+ l = 2+0 = 2, 2p, n+ l = 2+1 = 3, 3s, n+ l = 3+0 = 3
3p, n+ l = 3+1 = 4, 3d, n+ l = 3+2 = 5, 4s, n+ l = 4+0 = 4,
4p, n+ l = 4+1 = 5, 4d n+ l = 4+2 = 6, 4f, n+ l = 4+3 = 7
1s orbital has least energy because it has lowest n+l value, 2s orbital has greater energy than 1s because its n+ l value is 2 which is more than n+l value for 1s orbital.
If two sub shells or orbitals have same n+ l value , the sub shell or orbital with lower n value will have lower energy.
3d and 4p has same n+ l value (5) , but 3d will have lower energy because it has lower n value. For 3d , n value is 3 and for 4p , n value is 4.