The one rule that matters now
In current versions, hostile mobs spawn only where the block light level is 0 — a single torch’s radius (light 14 at the torch, minus 1 per block away) makes every block within about 12 blocks spawn-safe. This is why lighting a perimeter, not just your room, is the real security upgrade.
Torch spacing for a lit base
Torches on the ground every 12 blocks along walls keep outdoor areas clear; for interiors place one per room and one in every unlit corner recess. Slabs (bottom half) and carpets also block spawns on top of them — moats, slabs and overhangs are the passive defense for large roofs, the most forgotten spawn surface.
Caves, farms and the sky
Cave exploration is a light-management game: wall off unexplored tunnels behind you. Mob farms invert the rule — they are dark boxes built far from your base, often over the ocean or high in the sky to minimize other spawnable surface. If your farm underperforms, you almost certainly have unlit caves underneath it eating the spawn cap.