On the periodic table: Why are groups of elements organized by 'letter'
The letters are related to the electron orbitals, which were originally observed through spectroscopy. The lines shown in the spectroscope were named sharp, principal, diffuse and fine (or fundamental).

With a strong magnetic or electrostatic field, these separate into one, three, five or seven lines, or energy levels. There can be up to two electrons (with opposite spin) with the same energy level, according to the Pauli exclusion principle, so this implies there can be double the numbers above, or 2 s electrons, 6 p electrons, 10 d electrons and 14 f electrons. Thus, the Periodic Table is based on the number of electrons in each elements orbitals.