How BGP routing works: how the internet picks a path
BGP is how networks exchange routes. How a route gets chosen, why traffic detours, transit and peering, hijacks and leaks, what RPKI fixes, and reading a topology chart.
7 min readPart 15 of 16
On this page
The internet is made of tens of thousands of independent networks (see What is an ASN?), and data on its way from your home to a website usually crosses several of them. How does each network know where to send it next? Through BGP, the Border Gateway Protocol: neighboring networks tell each other "these addresses can be reached through me", and each network decides for itself where to send traffic based on what it hears.
What BGP exchanges
Two neighboring networks set up a BGP session and send each other two kinds of message:
- Announcements: these prefixes can be reached through me, along with details such as the AS path.
- Withdrawals: a prefix I announced earlier can no longer be reached through me.
Each network stores the routes it receives in its routing table and passes them on to its other neighbors according to its own rules, adding its own ASN to the front of the AS path each time (see the diagram in What is an ASN?). The global routing table holds more than a million routes; for how big their prefixes are, see CIDR notation explained. Any announcement or withdrawal spreads across the internet within seconds to minutes.
BGP only deals with traffic between networks. How a network forwards traffic internally is handled by other protocols, chosen by each network.
How a route gets chosen
A network often hears about the same prefix from several neighbors. Its routers pick one in roughly this order:
- The most specific prefix wins. Given a
/22and a/24inside it, traffic for the/24follows the/24; see CIDR notation explained. - The cheapest relationship wins. Routes from customers who pay you beat routes from peers, which beat routes from providers you pay.
- The shorter path wins. Fewer networks in the AS path is better.
- Finally, a few tie-breakers, such as preferring the nearest exit.
Your network, AS64500, hears three routes to 203.0.113.0/24
Notice that none of these is "which path is faster". BGP doesn't measure latency or bandwidth; business relationships and the number of networks decide. That's why traffic between two neighboring countries sometimes travels somewhere far away and back when their ISPs don't connect directly, and why the path there and the path back are often different; see Ping and traceroute.
Business relationships between networks
| Relationship | Who pays | How routes flow |
|---|---|---|
| Customer and provider | The customer pays | The provider tells the internet about the customer, and the customer about the internet |
| Peering | Usually nobody | Each side only shares its own and its customers' routes |
| Between Tier 1s | Nobody | They all peer with each other and buy transit from no one |
Smaller networks buy transit from bigger ones, which carry them to the rest of the internet. Networks of similar size often peer, exchanging only traffic between their own users and saving on transit. A lot of peering happens at internet exchange points, where hundreds of networks connect to each other in the same building. There's a diagram of both relationships in What is an ASN?.
At the top are a dozen or so Tier 1 networks, such as Lumen (AS3356), Arelion (AS1299) and NTT (AS2914). They all peer with each other and reach the entire internet without buying transit from anyone.
These relationships come with one more rule about passing routes on: routes learned from a provider or a peer are only passed to your own customers, never to other providers or peers. Otherwise other people's traffic would flow through a network that was never meant to carry it.
When you reach a site abroad from China, which ISP and which backbone you're on, and which international provider it connects to, can make a big difference to latency and stability. When people talk about a server's "route quality", this is what it comes down to.
When routing goes wrong
BGP trusts what its neighbors tell it by default, so a mistake in one place can affect the whole internet:
- Hijacks: a network announces address space that isn't its own, and traffic to those addresses goes to the wrong place; see IP address history.
- Leaks: a network breaks the rule above and passes routes learned from one provider to another. Huge amounts of traffic pour into a small network, taking detours, getting congested or failing outright.
- Withdrawals: pulling your own routes makes you vanish from the internet.
June 2019: a route leak
From 10:30 UTC on 24 June 2019, a BGP optimizer used by DQE, an ISP in Pennsylvania, split the routes it received into more specific prefixes, turning Cloudflare's 104.20.0.0/20, for example, into two /21s. DQE passed these routes to its customer Allegheny Technologies, which passed them on to its other provider, Verizon. Verizon didn't filter them and told the whole internet.
For example104.20.0.0/20104.20.0.0/21104.20.8.0/21
Cloudflare's write-up points out that any one of three safeguards at Verizon would have stopped the leak: a limit on how many routes each customer may send; filtering on the prefixes customers have registered in IRR databases; or RPKI validation, covered below. Cloudflare's ROA for these addresses only allows announcements up to /20, so the split-off /21s would have been marked invalid.
October 2021: Facebook withdraws itself
On 4 October 2021, during maintenance, a command meant to assess Facebook's backbone capacity took down the whole backbone. Facebook's DNS servers have a rule: if they can't reach the data centers, they withdraw their BGP announcements so they don't send users somewhere broken. This time every location lost contact at once, so all the routes to the DNS servers were withdrawn. The servers were still running, but no one in the world could reach them; facebook.com stopped resolving, and Facebook, Instagram and WhatsApp all went down.
4 October 2021, UTC
15:40 Peak of route changes from Facebook
15:50 facebook.com stops resolving
21:00 Facebook’s routes start coming back
21:20 facebook.com resolves again
You can still see this in RIPEstat. RIPE snapshots every collector peer's routing table every eight hours. 129.134.30.0/24 holds one of Facebook's DNS servers, a.ns.facebook.com (129.134.30.12), and the last column of each record is how many peers saw it:
curl -s "https://stat.ripe.net/data/routing-history/data.json?resource=129.134.30.0/24&starttime=2021-10-03&endtime=2021-10-06" \ | jq -r '.data.by_origin[].prefixes[] | select(.prefix == "129.134.30.0/24") | .timelines[] | "\(.starttime) \(.endtime) \(.full_peers_seeing | floor)"'2021-10-03T00:00:00 2021-10-04T15:59:59 3412021-10-05T00:00:00 2021-10-05T23:59:59 3412021-10-06T00:00:00 2021-10-06T07:59:59 339In the 16:00 snapshot on 4 October, the route wasn't in any peer's routing table, so the record breaks; by the midnight snapshot on 5 October it was back.
CKIP's global network status page lists high-confidence hijacks and route leaks from the last seven days, and you can filter by country to see whether the networks you care about are affected.
RPKI: signing announcements
To fight hijacks, more and more networks use RPKI. The holder of an address block publishes a ROA through its regional registry saying "only this ASN may announce these addresses, and no more specifically than this prefix length". Other networks check incoming routes against it, with three possible results:
- Valid: the origin matches the ROA.
- No ROA: the block has no ROA, so there's nothing to check against.
- Invalid: the origin or prefix length doesn't match the ROA, and networks that validate drop the route.
RIPEstat can run this check for you. The three lines below are: Cloudflare itself (AS13335) announcing 1.1.1.0/24; another network (here the documentation ASN AS64496) announcing the same block; and Cloudflare announcing a /25, more specific than its ROA allows:
for q in AS13335,1.1.1.0/24 AS64496,1.1.1.0/24 AS13335,1.1.1.0/25; do \ curl -s "https://stat.ripe.net/data/rpki-validation/data.json?resource=${q%,*}&prefix=${q#*,}" \ | jq -r '"\(.data.resource) \(.data.prefix) \(.data.status)"'; \ done13335 1.1.1.0/24 valid64496 1.1.1.0/24 invalid_asn13335 1.1.1.0/25 invalid_lengthThe second is what a hijack looks like, and the third is what the split routes of 2019 look like. Most routes on the internet are now covered by a ROA:
IPv41,085,140 routes
Valid 71.5%No ROA 28.5%Invalid: 36
IPv6260,814 routes
Valid 83.1%No ROA 16.9%Invalid: 10
Invalid routes are almost invisible, but not because nobody announces them. 26,560 invalid IPv4 routes show up in at least one peer's routing table, yet half of them are seen by just one peer and only 36 reach 100 peers; half of the valid and no-ROA routes are seen by 329 peers or more. With more networks validating, invalid routes no longer get far. The BGP routing security section of the global network status page also shows how the global routing table splits across these three groups.
RPKI only checks the start of the path, meaning who's announcing. An impostor who pretends in the AS path to be connected to the real holder still has the right origin, so it passes. A way to validate the whole path, called ASPA, has each network register its providers in RPKI; it's still being rolled out, and by 26 November 2026, 4,328 networks had registered.
Reading CKIP's BGP topology chart
Look up an IP or ASN on CKIP and the BGP topology chart at the bottom of the page shows the network's paths up to the Tier 1s:
- The network itself is on the left, followed by upstream levels 1, 2 and 3 and then the Tier 1 backbones. Paths that pass through a second Tier 1 are drawn on the far right.
- The percentage next to each network is the share of observed paths that pass through it. The big ones are its main providers.
- If the network is itself a Tier 1, the chart says so.
The chart shows which providers a network buys transit from and how many Tier 1s it reaches. The more providers it has, the less likely it is to go offline when one of them has trouble.
The chart is drawn from a sample of AS paths seen by route collectors around the world, which has two limits. The order along a path shows how traffic flows, not the business relationships between networks. And many peering links aren't visible to the collectors, so the chart shows only part of a network's real connections.