Short answer
BGP (Border Gateway Protocol) is how the tens of thousands of separate networks on the internet tell each other which IP addresses they can deliver traffic to. Each network, identified by its ASN, announces its IP prefixes to its neighbours, which pass them on with their own ASN added, so every router learns a path to every part of the internet.
Announcing prefixes
Google holds the block 8.8.8.0/24. Its routers, in AS15169, tell every network they connect to: "send traffic for 8.8.8.0/24 to me". Each neighbour passes that on to its own neighbours, adding its ASN to the front of the AS path. A few seconds later a router on the other side of the world might hold:
8.8.8.0/24 via AS path 4788 6939 15169
meaning "through TM (4788), then Hurricane Electric (6939), to Google (15169)". If Google stops announcing, it sends a withdrawal and the route disappears everywhere. You can see the prefix and its origin ASN on 8.8.8.0/24.
The version in use is BGP-4 (RFC 4271). Routers talk to each other over TCP port 179, in sessions set up by agreement between the two networks. BGP between different networks is called eBGP; inside one network, iBGP.
How routes are chosen
A router often learns several paths to the same prefix. Two rules matter most:
- The most specific prefix wins. Traffic to 8.8.8.8 follows a route for 8.8.8.0/24 rather than one for a broader 8.0.0.0/9, whatever the path length. This is longest prefix match.
- Among equal prefixes, policy decides. Networks prefer routes that earn or save money: from customers first, then from free peers, then from paid transit providers. Only after that does a shorter AS path win.
So BGP picks routes by business relationships, not by speed, which is why traffic sometimes takes surprising detours. To keep routing tables manageable, most networks ignore IPv4 prefixes smaller than a /24 and IPv6 prefixes smaller than a /48.
Transit and peering
Small networks buy transit: an upstream provider carries their traffic to the rest of the internet. Networks of similar size often peer, exchanging traffic between their own customers for free, either over a direct link or at an internet exchange point (IXP), a shared switch where hundreds of networks meet. The largest backbone providers, which reach everything through peering alone, are called tier 1 networks.
Hijacks and leaks
BGP was designed on trust: a router largely believes what its neighbours say. Things go wrong when a network announces addresses it does not hold.
- Hijacks: in 2008 a Pakistani ISP announced a more specific prefix of YouTube's addresses to block it at home; the announcement spread worldwide and took YouTube offline for about two hours. Deliberate hijacks have been used to steal cryptocurrency and send spam from borrowed addresses.
- Route leaks: a network passes routes learned from one provider on to another, accidentally becoming a path for traffic it cannot handle.
- Self-inflicted outages: in October 2021 a configuration error caused Facebook to withdraw the routes to its own DNS servers, and its services were unreachable for about six hours.
RPKI
The main defence is RPKI (Resource Public Key Infrastructure). Address holders publish signed Route Origin Authorisations (ROAs) through their regional registry, stating which ASN may originate each prefix and how specific the announcements may be. Routers that perform route origin validation (RFC 6811) drop announcements that contradict a ROA. Many large networks now filter this way, which stops most accidental hijacks, though it checks only the origin, not the whole path.
BGP on this site
Every IP lookup shows the announced prefix and its origin network, which come from BGP data: connection.route and connection.asn in the API. Browse networks in the ASN directory, see the prefixes one network announces on its page such as AS15169, and inspect a single block on its prefix page.
[ FAQ ]
Frequently asked questions
Is BGP used inside home networks?
No. Home and office networks use a default route to their ISP. BGP runs between networks that connect to more than one other network, such as ISPs, cloud providers, CDNs and large companies, and inside their backbones.
What is a BGP hijack?
It is when a network announces IP prefixes that belong to someone else, by mistake or on purpose, so that some or all traffic for those addresses goes to the wrong network. RPKI route origin validation blocks many of these.
Why does BGP not choose the fastest route?
BGP does not measure speed or latency. It chooses by the most specific prefix and then by each network's policy, which mostly follows business relationships, with AS path length as a tie-breaker.
What is the smallest prefix that can be announced?
Most networks accept IPv4 announcements up to a /24 (256 addresses) and IPv6 announcements up to a /48. Longer prefixes are usually filtered out.
Last updated · All articles · API docs