Tutorial:Spawn-proofing

Hostile mobs spawn in and around your builds at zero block light level and at most in 7 internal sky light level. Mobs such as creepers have the potential to destroy your creations, while others may attack you. There are many ways of preventing hostile creatures from spawning.
Basic spawn-proofing
Light blocks: One of the most basic ways to prevent mob spawning is by placing torches or other light sources. These increase the light level around them, stopping hostile mobs from spawning. Other blocks such as glowstone or shroomlight emit higher light levels, but are harder to come by. This method does not work with mobs whose spawning does not rely on low light level, such as slimes, magma cubes, ghasts and hoglins. The most efficient distance for torches is about 14 blocks to the next torch.
Slabs, carpets, stairs and partial blocks: Mobs cannot spawn on blocks that are less than a full block in height. Areas covered in bottom slabs are unable to spawn mobs, no matter the light level, although double slabs, top slabs and upside-down stairs are still spawnable. Also, dirt path and farmland are partial blocks (15/16th of a block in height) and cannot be spawned upon. However, mud, soul sand and snow layers of thickness of 8 allow mob spawning, despite being 14/16th of a block in height.
Transparent blocks
- Mobs also cannot spawn on top of transparent blocks, such as glass, or partially transparent blocks, such as leaves. Tinted glass doesn't allow mob spawning, despite blocking all light unlike regular glass and stained glass.
Snow layer
- Snow layers of thicknesses 2 to 7 prevent hostile mobs from spawning.
(only one layer of snow doesn't work, as it is not possible to step on it)
- Mobs cannot spawn on buttons, redstone wires, redstone repeaters, redstone comparators, levers, pressure plates, and all types of rails. This does not include string.
- Mobs other than aquatic mobs are unable to spawn in water. Mobs other than striders are unable to spawn on lava.