The maximum number of electrons in a subshell depends on the number of orbitals in the subshell.
An orbital is a region in space where an electron is likely to be found. Each orbital can contain two electrons. The shapes of the orbitals are shown below.
Note that the number of columns in the blocks of the periodic table correspond to the maximum number of electrons in the subshells.