Here's my explanation.
The structure of energy shells
A shell consists of all orbitals with the same principal quantum number
All energy shells except
Subshells in a hydrogen atom
In a hydrogen atom, all the subshells in a shell have the same energy.
The number of orbitals and electrons in each subshell is:
This gives the maximum number of electrons in each shell as 2, 8, 18, 32, 50.
Subshells in other atoms
In atoms with more than one electron, the energies of the subshells change because of repulsions between the electrons.
Within a shell, the relative energies are in the order
(a) Potassium atoms
The number of electrons in each shell becomes, 2, 8, 8, 2 instead of 2, 8, 10.
(b) Tin atoms
The number of electrons in each shell becomes, 2, 8, 18, 18, 4 instead of 2, 8, 18, 22.