Minecraft wiki entry for Spawn, associated text: There must be no players or the world spawn point within a 24 radius block distance (spherical) of the spawning block
The number of loaded mobs of that type must be less than the mob cap for that type. (I.e. the corresponding mobcap must not be full)
The mob's collision box upon spawning must not collide with another collision box. A mob cannot spawn inside of anything that would collide with it upon spawning.
The mob's collision box must not intersect with a solid block.
For all mob types excluding passives and fish, spawns fail unless within a 128 radius block sphere around the player. For fish, spawns fail unless within a 64 block radius of the player. [2]
/gamerule doMobSpawning is true
For non-aquatic mobs, the spawning block and the block above that cannot be rails, powered rails, detector rails, activator rails, redstone components, wither roses (except for wither skeletons) or sweet berry bushes (except for foxes).