Routing between networks with BGP
The Internet is tens of thousands of autonomous systems, each routing inside itself as it likes, and BGP lets them announce which prefixes they can reach along with the whole path of systems, so each chooses routes by business policy as much as by length and refuses any path that already contains itself.