Between 24 and 32 blocks away for random spawns, less than 16 for spawners. Here's a handy diagram. You should be at least 24 blocks away from the closest edge, but within 128 blocks of the farthest edge. (Distance above or below also count) The max number of mobs than can pile up will also be capped, so you should try to light up caves as much ...