A packet leaving your phone for a server in Frankfurt crosses a dozen independent companies that have never coordinated their engineering, run different equipment, and often actively compete. Yet the packet arrives, usually in tens of milliseconds. There is no master map of the Internet stored anywhere; no committee computes the routes. Instead the whole global structure emerges from thousands of networks each shouting to their neighbours, "here are the destinations I can reach, and here's the path to them." That gossip protocol is BGP, the Border Gateway Protocol — the single piece of software that glues the Internet into one network.
We have already seen
BGP does not route between computers or even between routers; it routes between autonomous systems. An AS is a set of IP prefixes and routers under a single administrative control with one consistent routing policy — an ISP, a big cloud, a large university. Each AS is stamped with a globally unique Autonomous System Number (ASN), handed out by the regional registries.
104.16.0.0/12 — meaning "traffic for these addresses should ultimately come to me."
There are roughly 75,000+ active ASes today, and the global BGP routing table has grown past ~950,000 IPv4 prefixes — a number every core router must hold in memory and search on every packet, which is why router memory (the "FIB") is a real and expensive constraint.
Interior protocols like OSPF flood link states; simple distance-vector protocols advertise only a
distance. BGP does something cannier — it is a path-vector protocol: every route
advertisement carries the entire list of ASes the route passes through, the
AS-path. When AS3 tells its neighbour AS4 "I can reach 203.0.113.0/24 via
AS-path 3 2 1," AS4 records the route and, if it chooses to re-advertise it, prepends
its own ASN: it tells AS5 the path is 4 3 2 1.
Carrying the full path buys two things a plain distance never could:
Watch a prefix originated by AS1 ripple outward, each AS prepending itself so the path grows as it travels:
This is the part that surprises everyone: BGP's real decisions are commercial. Networks interconnect in two economically different ways:
| Relationship | Who pays | What routes are shared |
|---|---|---|
| Transit (customer ↔ provider) | Customer pays the provider per bit | Provider gives the customer routes to the whole Internet |
| Peering (peer ↔ peer) | Usually settlement-free (nobody pays) | Each shares only its own + its customers' routes, not the whole Internet |
These relationships drive the famous valley-free rule (Gao–Rexford): a network happily carries traffic for free if doing so earns money or reaches a paying customer, but it will not spend money to carry traffic that benefits a competitor. Concretely, an AS prefers routes in this order: customer > peer > provider — because a customer route earns revenue, a peer route is free, and a provider route costs money.
BGP encodes this with attributes, applied in a strict order when choosing among candidate routes for the same prefix:
The upshot: the path your packets take is often not the geographically or topologically shortest one — it is the cheapest one for the networks in between. Routing on the Internet is an economic phenomenon wearing an engineering costume.
BGP wears two hats. eBGP (external) runs between different ASes — this is the part that swaps routes across company boundaries and prepends ASNs. iBGP (internal) runs within a single AS, distributing the externally-learned routes to all the AS's own border routers so they agree on how to leave the network. A subtlety: to prevent internal loops, a route learned via iBGP is not re-advertised to another iBGP peer — which is why large ASes need route reflectors or a full mesh of iBGP sessions. Same protocol, two very different jobs.
Here is the uncomfortable truth. Classic BGP has no built-in authentication of who owns what.
When an AS announces "I originate 203.0.113.0/24," its neighbours largely
believe it. That trust, combined with a rule that more-specific prefixes win,
makes two disasters possible:
/24
inside someone's /22 — pulls the world's traffic to the impostor. In the famous
2008 incident, Pakistan Telecom (AS17557) announced a more-specific route for YouTube
intending to block it locally; the announcement leaked to its provider and globally, taking
YouTube offline for about two hours. A 2018 hijack rerouted Amazon Route 53 DNS traffic to steal
cryptocurrency.
The defences are being deployed but are still incomplete: RPKI (Resource Public Key
Infrastructure) cryptographically signs "AS
The seductive wrong model is "BGP finds the best route." It does not. BGP finds a route that is consistent with every network's business policy, and among those, prefers a short AS-path — but AS-path length is a crude proxy. One "hop" might be a transcontinental AS spanning 10,000 km; another might be a tiny local network. A path of two large ASes can be slower than a path of four small ones. BGP has no idea about latency, bandwidth, or congestion; it counts ASes and obeys money.
So your traffic can take a bizarre detour — Toronto to Montreal via New York, or two European users' packets routed through the US — not because it is shorter, but because that is the path the commercial relationships allowed. Never assume the BGP path is the geographically or performance-optimal one; it is merely the policy-legal one with the fewest AS hops.