Each shell is split into subshells with different shapes and energies: s (1 orbital, up to 2 electrons), p (3 orbitals, up to 6), d (5 orbitals, up to 10) and f (7 orbitals, up to 14). Shell 2 has 2s and 2p, so it holds 2+6=8; shell 3 has 3s, 3p and 3d, so it holds 18. A configuration lists each occupied subshell with its electron count as a superscript: sodium is 1s22s22p63s1, and the superscripts add up to its 11 electrons.
Electrons fill the lowest-energy subshell available, the Aufbau principle. The order is 1s, 2s, 2p, 3s, 3p, 4s, 3d, 4p, and the surprise is 4s before 3d: potassium's 19th electron goes into 4s, not 3d. Within a subshell, electrons spread out one per orbital before any pair up (Hund's rule), so nitrogen's three 2p electrons sit in three separate orbitals. Noble-gas shorthand saves writing: sodium becomes [Ne]3s1.
Filling order is not removal order. Iron is [Ar]4s23d6, but Fe2+ is [Ar]3d6: the 4s electrons, in the outermost shell, leave first. A few atoms also rearrange for stability: chromium is [Ar]4s13d5 and copper [Ar]4s13d10, because half-filled and filled d subshells are especially stable. The simpler shell picture (2, 8, 8, 2 for calcium) tells you how many electrons are in each shell; a configuration also tells you which subshell they occupy.
Think of it like this. Filling subshells is like booking hotel rooms priced by energy rather than by floor: each room type (subshell) has a fixed number of beds, guests take the cheapest available first, and one room type on floor 4 (4s) costs less than the best rooms on floor 3 (3d). Within a room type, guests take empty beds before sharing one.
Core idea. Electrons fill subshells (s, p, d, f) in order of increasing energy, spreading out within each before pairing, and the resulting configuration accounts for the periodic table's blocks, an atom's valence electrons and the ions it forms.