How Does BGP Work? Autonomous Systems, AS Paths, and the Policy That Routes the Internet

The decision rule, policy first, distance second. BGP picks the path each network prefers. Speed comes second, and distance comes third. A shorter route loses to a longer route whenever the longer route matches the network’s policy, and that single rule explains nearly everything the protocol does.

The internet has no center. Tens of thousands of separate networks carry traffic for each other, and each one decides for itself which neighbor receives a packet next. BGP is the protocol those networks use to share routing information, and the table below lists the order a router applies when several routes lead to the same destination.

StepWhat the router comparesHow it decides
1. Local preferenceA policy number each network sets on a routeHighest wins
2. Locally originated routeA route the network announces itselfWins over a learned route
3. AS path lengthCount of networks in the pathShortest wins
4. Origin codeHow the route entered BGPIGP beats EGP, EGP beats incomplete
5. MEDA hint sent by the neighboring networkLowest wins, compared only between routes from the same neighbor
6. eBGP over iBGPWhere the route was learnedA route from another network wins
7. Router IDTiebreaker of last resortLowest wins

Cisco routers add one more step before all of these: a local weight number, which never leaves the router. Other vendors start at local preference. A router walks the list from the top and stops at the first step where the candidate routes differ. Two routes with the same local preference move to the AS path length, and the first difference ends the comparison. Distance enters the decision only after policy has had its say.

Does BGP pick the fastest route?

No. BGP measures no speed. It compares policy numbers first and counts networks second. A two-network path through a paid transit link can sit unused while traffic takes a four-network path through a free peering link, because the network set a higher local preference on the peering link.

The internet is tens of thousands of separate networks

An autonomous system is a collection of routers under one administration that presents one routing policy to the rest of the internet. Your home ISP runs one. A university runs one. Google runs one, and Cloudflare runs one. Each system controls a set of IP address blocks, called prefixes, and each system carries a unique number, its ASN. The cloud platforms run some of the largest of these systems, and how cloud computing works at their scale depends on those announcements reaching every other network.

The numbers make the scale concrete. Google’s network is AS15169. Cloudflare’s is AS13335. AT&T’s is AS7018. A prefix looks like 8.8.8.0/24, which holds 256 addresses, and the number after the slash says how many addresses the block contains. A 2026 industry count puts the full routing table near 950,000 IPv4 prefixes and 200,000 IPv6 prefixes, and every border router that speaks BGP holds a copy of that table.

BGP is old for internet infrastructure. The first version appeared in 1989, and the version in use today, BGP-4, is defined in RFC 4271. It began as a stopgap and became the core routing protocol because nothing else handled policy between networks.

A live query of the RIPEstat looking glass on 6 November 2026 returned 366 current BGP paths to Google’s 8.8.8.0/24 prefix and 361 to Cloudflare’s 1.1.1.0/24. Most paths crossed exactly two autonomous systems. The shortest path to Google’s prefix ran through a single transit network, AS15692, then straight into AS15169. The longest ran through five: 46997, 38008, 38008, 3491, then 15169. The same prefix reaches the world through hundreds of routes at once, and each network picks its own.

One detail in that longest path shows a policy tool at work. AS38008 appears twice in a row. A network repeats its own number in the path to make the route look longer, which pushes other networks toward a different exit. Engineers call the move AS path prepending, and it works because path length is one of the steps in the selection order.

Some networks announce one prefix from many places. A content delivery network announces the same addresses from dozens of autonomous systems, so the nearest copy answers. That practice is called anycast, and BGP is the mechanism that makes the nearest copy win.

Bar chart of 366 live BGP paths to 8.8.8.8 measured on 6 November 2026, most crossing two autonomous systems

How many networks make up the internet?

Tens of thousands of autonomous systems, each with its own number and its own policy. The exact count shifts as networks join and leave, and no single list stays current for long. A RIPEstat query run on 6 November 2026 saw 366 live paths to one Google prefix from 23 route collectors, which shows how many networks touch even a single destination.

One request across three networks

A request for a web page crosses several networks before it arrives. The journey below follows a real path measured on 6 November 2026, from a device to Google’s public DNS address, 8.8.8.8.

  • DNS turns google.com into an address in a Google prefix, before any routing decision happens.
  • The home router forwards the packet to the ISP.
  • The ISP’s border router checks its BGP table. Two routes lead to Google’s prefix, and local preference picks the one through AT&T, AS7018.
  • The packet crosses into AT&T’s network, then into Google’s AS15169, where the server answers.

The handoff works like a relay of couriers. Each courier knows only the next depot, and the parcel changes hands until it reaches the address on the label. No courier plans the whole route, and no single network plans the whole internet.

Google’s routers pick their best path back, and that path can differ from the one the request took. Networks choose independently, so the outbound and return paths often differ, which is called asymmetric routing. A problem on the return path stays invisible to anyone watching only the outbound direction.

A reader can check the first step of any such journey. Public tools map an IP address to its ASN, and the RIPEstat looking glass shows the live AS path to any prefix. The paths named above came from that public record on 6 November 2026.

Diagram of two live BGP paths to Google DNS, a two network path through AS15692 and a five network path through Montevideo

The four messages that keep peers talking

Two routers become BGP peers by opening a TCP connection on port 179. TCP carries the conversation, so BGP inherits retransmission and ordering instead of building its own. That choice is why BGP is described as an application-layer protocol: it runs on top of TCP, while the routes it advertises describe layer 3 prefixes.

The session moves through states with plain names: Idle, Connect, Active, OpenSent, OpenConfirm, and Established. A session that reaches Established stays up for weeks or months. The two routers then trade four message types.

  • OPEN starts the session. It carries the AS number, the hold time, and the capabilities each side supports.
  • KEEPALIVE is a short message sent every 60 seconds. It says the session is alive and the peer is still there.
  • UPDATE carries new or withdrawn routes, with the path attributes that describe each one.
  • NOTIFICATION reports an error and closes the session.

After the session opens, the peers exchange their full routing tables once, then send only changes. A route that stays stable for months generates no UPDATE traffic at all. A silent peer is declared dead when the hold time expires, 180 seconds by default, which is three keepalive intervals. The 60-second keepalive and the 180-second hold time are the protocol’s heartbeat and its timeout, and both numbers are defaults an operator can change.

The same session can carry IPv6 prefixes alongside IPv4, through multiprotocol extensions defined in RFC 4760. One peering carries both address families, which is how networks run the two side by side.

Why does BGP run on TCP?

Reliability. A routing table with close to a million entries cannot survive lost messages, so BGP borrows TCP’s retransmission and ordering. The cost is a slower start: a session needs a full TCP handshake before the first route moves, and a broken session needs a full table exchange to recover.

Four step diagram of the BGP messages OPEN, KEEPALIVE, UPDATE, and NOTIFICATION between two peers

eBGP and iBGP: the same protocol, different rules

BGP runs in two modes, and the mode changes the rules. External BGP, eBGP, runs between routers in different autonomous systems, and it is the mode that stitches the internet together. Internal BGP, iBGP, runs between routers inside one autonomous system, and it carries external routes across a large network without involving the interior routing protocol.

RuleeBGP (between networks)iBGP (inside one network)
Where it runsBetween different autonomous systemsInside one autonomous system
AS pathAdds its own ASN to the pathLeaves the path untouched
Next hopSets the next hop to itselfLeaves the next hop untouched
Time to live1 by default, so peers are usually direct neighbors255, so peers can sit anywhere in the network
Full mesh neededNoYes, unless route reflectors or confederations are used

The full-mesh rule is the expensive one. Every iBGP router must peer with every other iBGP router, so a network with 100 routers needs 4,950 sessions. Route reflectors break that rule: a few routers reflect routes to the rest, and the same 100-router network runs on about 100 sessions. Confederations split one large system into smaller sub-systems that look like one ASN from outside, and they solve the same problem a different way.

Both modes can attach policy tags to routes. A community is a 32-bit tag that travels with the announcement and tells the receiving network how to treat it. NO_EXPORT means the route stays inside the receiving network, and NO_ADVERTISE means it goes no further at all. Providers publish lists of their communities, and customers use them to steer traffic without a phone call.

When BGP goes wrong: leaks and hijacks

BGP trusts the networks that speak it. The protocol has no built-in check that a network owns the addresses it announces, so a mistake or a malicious announcement can spread across the internet before anyone notices. Two failures show the two shapes of the problem.

In February 2008, Pakistan Telecom announced YouTube’s prefix, 208.65.153.0/24, as if it owned those addresses. Networks around the world accepted the announcement, and YouTube went unreachable for about two hours until the bad route was withdrawn. The announcement was a mistake, not an attack, and the damage came from how fast good routers believed it.

Facebook withdrew its own BGP routes in October 2021 during a configuration change, and the outage lasted about six hours. Its own services vanished from the internet, including the DNS servers that translate facebook.com, so the company’s own engineers struggled to reach the systems that could fix it. The cause was an internal error, and the scale came from BGP doing exactly what it was told.

Leaks and hijacks differ in intent and in shape. A leak spreads a real route beyond its intended scope, usually through a configuration error. A hijack announces addresses the sender does not own, which can redirect, intercept, or discard traffic. Both start with one announcement that other networks trust, and both are hard to detect from inside the affected network.

How networks defend the route table now

The main defense is a signed record of who may announce what. RPKI, the Resource Public Key Infrastructure, lets a prefix owner publish a Route Origin Authorization, a signed statement that names the ASN allowed to announce the prefix. Networks that validate origins reject announcements that contradict the signed record. Adoption keeps growing, and it is still far from universal, so validation protects the networks that run it and leaves the rest exposed.

Prefix filtering adds a second layer. A network that buys transit from a provider can hand the provider a list of the prefixes it owns, and the provider drops announcements outside that list. A firewall filters packets by rules, and prefix filtering applies the same idea to route announcements.

External monitoring adds the third layer. A network watches its own prefixes from route collectors around the world, and an unexpected origin ASN triggers an alert within minutes. The same public records serve anyone: the RIPEstat looking glass shows the live path to any prefix, and public tools map an IP address to its ASN.

Three checks take minutes. Look up the ASN behind an IP address you use every day. Read the live AS path to 8.8.8.8 in the RIPEstat looking glass and count the networks. Check whether a prefix you care about carries a valid ROA. Each check shows one layer of the system that carries every page load.

Replacing BGP means coordinating tens of thousands of independent networks, so the defenses work around the trust model instead of waiting for a new protocol.

Final Words

The next step takes five minutes. Pick an IP address you use every day, look up its ASN, and read the live AS path to it in the RIPEstat looking glass. Count the networks in the path, and check whether the prefix carries a valid ROA. Those two numbers say more about how the internet reaches you than any diagram can.

Frequently asked questions

What is BGP in simple terms?

BGP is the protocol that independent networks use to tell each other which IP addresses they can reach. Each network announces its prefixes to its neighbors, the neighbors pass the announcements on, and every network builds a table of paths from those announcements.

What is an autonomous system number (ASN)?

An ASN is the unique number assigned to an autonomous system, the set of routers under one administration. Google’s network is AS15169 and Cloudflare’s is AS13335. The number appears in every AS path, so it identifies each network a route crosses.

Can BGP route around a country?

Partly. A network can set policy to avoid a transit network run by a provider it distrusts, and the AS path shows which networks the traffic crosses. Full avoidance needs control of every network on the path, which no single network has, and an ASN on its own does not name a country.

How long does it take BGP to spread a new route around the world?

Most networks learn a new route within a minute, and the whole internet usually converges in a few minutes. The exact time depends on how many networks sit between the announcement and the listener, and on timers such as the 30-second minimum interval between updates to the same peer on eBGP sessions.

Does BGP carry my data, or only routing information?

Only routing information. BGP messages carry prefixes, AS paths, and policy tags. Photos, messages, and page contents travel separately, inside packets that follow the routes BGP selected.

Can I see the BGP route my traffic takes?

Yes, from the outside. The RIPEstat looking glass shows the live AS path to any prefix from route collectors around the world. A traceroute on your own device shows router hops instead, which is a different view of the same journey.

user profile reference
Kaleem
Computer, AI and Web Technology Specialist | Web | + posts

Kaleem is a Computer Science graduate (Virtual University of Pakistan) and the founder and editor of Valley AI, where he publishes in-depth, tested guides on computer hardware, artificial intelligence, and how the internet works. Every guide is researched from primary sources, tested hands-on where possible, and updated when the facts change.

Leave a Comment