Minecraft wiki entry for Nether_portal, associated text: If any candidate portal block is found, then the game selects the closest one as determined by its distance in the new coordinate system (including the Y coordinate, which can cause seemingly more distant portals to be selected), and teleports the entity to the lowest connected portal block (this prevents players from being dropped from the top of tall portals). Note that the calculated distance is Euclidean distance, not taxicab distance. The distance computation between portals in the range is a straight-line distance calculation, and the shortest path is chosen, counting the Y difference.