Slimes in Minecraft spawn in two main types of locations:
- Slime Chunks: These are specific underground chunks where slimes can spawn regardless of light level. They spawn below layer Y=40 (or Y=39 in Bedrock edition) in the Overworld. About 10% of all chunks are slime chunks, and slimes can spawn there at any light level. These chunks are rare and can be identified by exploring underground and finding slimes spawning naturally
- Swamp Biomes: Slimes spawn on the surface in swamp and mangrove swamp biomes between layers Y=51 and Y=69, usually near the surface. They spawn only at night and require a light level of 7 or less, which is higher than for most hostile mobs that require light level 0. The spawn rate in swamps is influenced by the moon phase, with the highest spawn rate during a full moon. Slimes can spawn on solid or top-half blocks in swamps, even on some light-emitting blocks like redstone torches which emit light level 7
In summary, slimes spawn underground in slime chunks below Y=40 regardless of light, or on the surface of swamp biomes between Y=51 and Y=69 at night with light level 7 or less, especially during a full moon.