There are a couple rules that relates to the number 24 and somewhere close to the number 24.
As pointed by MrLemon in the comments the 24 block rule may refer to this as quoted from minecraft wiki
There must be no players and no player spawn points within a 24 block
distance (spherical) of the spawning block
This means that you should stand 24 blocks away from any thing that the mob can spawn at. Simplest way to do this is to Build it about 30 blocks above you, have the mob fall 22/23 blocks as explained below and stand there while afk-ing.
Do take note that 30 blocks away from the floor is the absolute limit for you to afk farm mobs. This is due to the follow fact quoted from minecraft wiki.
All mobs except slimes will stop wandering within 5 seconds if there
is no player within a 32 block radius. In this state, they will glance
around randomly, but they won't walk anywhere.
This means that if you want to make a mob farm, without pistons pushing them off, then the only way is for you to be within 32 blocks so that they would walk off naturally. However this has an exception.
Zombies can walk when there is a villager they can attack even if they are over 32 blocks from a player
This means that if you place a villager within the sight of a zombie mob farm, it will still move towards the villager even if you are beyond 32 blocks away. Although even with that, The outer limit that hostile mobs will despawn is 128 blocks away thus a play must always be within 128 blocks for the mob to spawn at all.
The 24 block rule can also apply to the distance at which the mob has to fall. This means that from the hole at which the mob starts to fall, to the ground where the mob lands at must be 24 or at minimum 23 blocks to have a guaranteed death.
This is due to the fall damage formula. An entity starts to recieve fall damage after falling for more than 3 blocks. For every block fallen after 3 blocks the entity recieve half a heart or 1 point of damage. This means that 23 blocks later it would have exceeded 10 hearts of damage for the entity and therefore making sure the entity dies.
The formula is as follows
(DistanceFallen - 3) / 2
hearts of damage
As pointed in the comments by Marco Geertsma, You can make this more efficient by having a 22 block drop instead of a 23 block drop. This would require you to perform the last hit to kill the mob but it would also grant you EXP in the process.
One way to do the 22/23 block fall interchangeably is to have pistons push up the block to make it 22 and pull it down to make it 23. This way, you can make it automatic when you want to afk and manual when you need the exp.
For further information you may want to refer to the minecraft wiki on
Mob spawning
http://minecraft.gamepedia.com/Spawn
Mob AI
http://minecraft.gamepedia.com/Mobs
Fall Damage
http://minecraft.gamepedia.com/Damage
Best Answer
My method uses scoreboards for detecting position. Since with scoreboards you can execute if a score is in a range.
Note: This will work in a infinite area, and may cause less lag then some other methods
Hovering your mouse over italicized words will give you a short explanation/tooltip
Important: You must be in a Minecraft version of at least 1.13 for this method to work
Preparation
In Minecraft, you need to create a scoreboard objective with a dummy critera. You can do that with the following command.
After Preparation
Next, you need to have in a Repeating Command Block or a Ticking Function a command that gets the
Pos[1]
of all players/entities and stores it in ourypos
scoreboard. The following command will accomplish that.If you want it to work for all entities, replace
@a
with@e
. Next, you need a Repeating Command Block or a Ticking Function with a command testing for players that have a ypos score of 122 or more and teleport them to 121 or lower. The following command accomplishes that.Again, if you want this to work with entities, change the
@a
to@e
Summary
This method stores the ypos of every player/entity in a scoreboard, then checks to see if the ypos value is greater than or equal to 122 and if so, it will teleport them down.