As the first electron shell contains only one sub-shell (the s sub-shell) and this contains only one orbital (which can hold a maximum of 2 electrons), the total number of electrons that the first shell can hold is 2.
(2) = 2
As the second electron shell contains two sub-shells (the s and p sub-shells) and as these contain one and three orbitals respectively (which can hold a maximum of 2 electrons each), the total number of electrons that the second shell can hold is 8, that is,
(2) + (2 + 2 + 2) = 8
Note that this is 2 electrons in the s sub-shell and 6 electrons in the p sub-shell.
As the third electron shell contains three sub-shells (the s, p and d sub-shells) and as these contain one, three and five orbitals respectively (which can hold a maximum of 2 electrons each), the total number of electrons that the second shell can hold is 18, that is,
(2) + (2 + 2 + 2) + (2 + 2 + 2 + 2 + 2) = 18
Note that this is 2 electrons in the s sub-shell, 6 electrons in the p sub-shell and 10 electrons in the d sub-shell.
As the fourth electron shell contains four sub-shells (the s, p, d and f sub-shells) and as these contain one, three, five and seven orbitals respectively (which can hold a maximum of 2 electronseach ), the total number of electrons that the second shell can hold is 32, that is,
(2) + (2 + 2 + 2) + (2 + 2 + 2 + 2 + 2) + (2 + 2 + 2 + 2 + 2 + 2 + 2) = 32
Note that this is 2 electrons in the s sub-shell, 6 electrons in the p sub-shell, 10 electrons in the d sub-shell and 14 electrons in the f sub-shell.