../

Autonomous systems & BGP

How tens of thousands of independently run networks agree on where every address lives: autonomous systems, who hands out numbers, interior and exterior routing, BGP messages and best-path selection, who pays whom, exchange points, anycast, leaks and hijacks, and the cables underneath. Builds on Networking fundamentals; IP addresses and DNS are in Communication networks.

A network of networks

Nobody runs "the internet". It is roughly 80,000 separately operated networks (79,920 in the CIDR Report (opens in a new tab) on 2026-11-11), each with its own routers, its own rules and its own business deals, that agree to pass traffic to each other. Think of countries: each builds its own roads and picks routes inside its borders, and border crossings exist only where two countries have signed an agreement.

Two separate jobs follow from that:

  • Inside one network, find the fastest path between its own routers. Every router can know the whole internal map, so this is a shortest-path problem.
  • Between networks, learn which network can deliver which addresses, and choose among offers by policy: who is a customer, who is paying, who is trusted. Nobody sees the whole map.
TermMeaning
autonomous system (AS)one network with one routing policy: an ISP, a cloud, a university, a large company
ASNthe AS's number, e.g. AS13335 (Cloudflare)
prefixa block of addresses, e.g. 203.0.113.0/24; routes are for prefixes, not single addresses
route"prefix X is reachable through this path of ASes"
BGPBorder Gateway Protocol, the one protocol networks use to exchange routes with each other
transitpaid access to the whole internet through a bigger network
peeringtwo networks swapping traffic for each other's customers, usually without payment
IXPInternet Exchange Point: a shared switch where many networks interconnect

Autonomous systems and ASNs

An autonomous system is "a connected group of one or more IP prefixes run by one or more network operators which has a single and clearly defined routing policy" (RFC 1930). A home or a small company with one ISP does not need one: its addresses are part of the ISP's AS. You need your own ASN when you connect to two or more providers (multihoming) and want to announce your own prefixes to both.

ASNs started as 16-bit numbers (0–65,535). They ran short, so RFC 6793 made them 32-bit (0–4,294,967,295); a 32-bit ASN is usually written as a plain number (AS4200000000), occasionally in "asdot" form (64086.59904).

RangeUse
0reserved, never appears in a path (RFC 7607)
1–64,495public 16-bit ASNs, assigned by registries
23,456AS_TRANS: stands in for a 32-bit ASN when talking to an old 16-bit-only router
64,496–64,511 and 65,536–65,551documentation and examples (RFC 5398); this sheet uses them
64,512–65,534private use (RFC 6996): inside your own network, never on the internet
65,535 and 4,294,967,295reserved (RFC 7300)
65,552–131,071reserved by IANA
131,072–4,199,999,999public 32-bit ASNs
4,200,000,000–4,294,967,294private use, 32-bit

Some well-known ASNs: AS15169 Google, AS13335 Cloudflare, AS16509 Amazon, AS8075 Microsoft, AS32934 Meta, AS3356 Lumen, AS1299 Arelion, AS2914 NTT, AS174 Cogent.

Who hands out numbers

Addresses and ASNs are unique worldwide because they are delegated down one tree:

LevelWhoHands out
topIANA (run by PTI, an affiliate of ICANN)large blocks and ASN ranges to the five RIRs
regionRIRs, Regional Internet Registriesaddresses and ASNs to members in their region
country, in some regionsNIRs, national registries (e.g. JPNIC in Japan)the same, within one country
memberLIRs, Local Internet Registries: mostly ISPs and hosting companiesaddresses to their customers
end usera company, university or homeuses them; a home gets one address or a small IPv6 block from its ISP
RIRRegion
AFRINICAfrica
APNICAsia-Pacific
ARINCanada, the United States and some Caribbean islands
LACNICLatin America and some Caribbean islands
RIPE NCCEurope, the Middle East and Central Asia
  • IPv4 is used up. IANA handed out its last free blocks in 2011 and the RIRs have since run through their normal pools; new IPv4 space mostly comes from transfers between holders, and prices are set by that market.
  • IPv6 is plentiful. An ISP typically receives a /32 (65,536 /48s) and gives each customer site a /48 or /56; see Building a network for plans.
  • Each RIR runs a public whois database (who holds what, abuse contacts) and a certificate authority for RPKI (who may announce what, see defenses).

Prefixes and aggregation

Routers don't store a route per address; they store prefixes. 208.65.152.0/22 means "the first 22 bits are fixed": 1,024 addresses, 208.65.152.0 to 208.65.155.255. To forward a packet, a router picks the matching prefix with the most fixed bits, the longest-prefix match: a /24 beats a /22 that also contains the address.

Aggregation announces one short prefix instead of many long ones. Four neighboring /24s become one /22:

Announced separatelyAggregated
208.65.152.0/24, 208.65.153.0/24, 208.65.154.0/24, 208.65.155.0/24208.65.152.0/22

Every route the whole internet accepts ends up in the table of every router that carries the full internet table (the default-free zone, routers with no default route). That table held about 1.09 million IPv4 and 265,000 IPv6 prefixes in November 2026 (CIDR Report), and routers keep it in fast, expensive memory. So operators aggregate where they can, and most networks filter out IPv4 prefixes longer than /24 and IPv6 prefixes longer than /48: those are the smallest blocks you can expect the whole internet to accept.

Networks still announce more-specific prefixes on purpose, to steer traffic (send /24s for half the block via one provider) or to keep working when a less specific route is hijacked.

Inside and between networks

Routing protocols split along the AS boundary. An interior gateway protocol (IGP) runs inside one AS; the exterior protocol, BGP, runs between them.

AS 64500 IGP inside: OSPF AS 64501 IGP inside: IS-IS 5 10 10 5 20 10 10 10 10 10 A B C D E G H I J F border border eBGP TCP 179 iBGP shortest B to E: 5 + 10 + 5 = 20 IGP link + cost: every router knows them shortest path (Dijkstra) eBGP: routes between ASes iBGP: eBGP routes, inside the AS
An IGP finds shortest paths inside an AS; BGP exchanges reachability between them
ProtocolKindRunsChooses byNotes
OSPFlink-stateinside an ASlowest total link costareas split big networks; OSPFv2 for IPv4, OSPFv3 for IPv6; common in enterprises
IS-ISlink-stateinside an ASlowest total link costruns directly over layer 2, not over IP; levels instead of areas; common in large ISP backbones
iBGPpath-vectorbetween routers of one ASBGP attributescarries routes learned outside across the AS
eBGPpath-vectorbetween ASespolicy, then AS paththe internet's routing protocol
  • Link-state: every router floods a description of its own links (OSPF LSAs, IS-IS LSPs), so all routers build the same map and each runs Dijkstra's shortest-path-first algorithm on it. Once a failure is detected it reconverges in well under a second to a few seconds, and it scales to networks of hundreds or a few thousand routers.
  • That cannot work between ASes: nobody would share their internal map, it would be far too big, and "shortest" is not what networks want; they want "cheapest and allowed".
  • Path-vector: BGP shares only "I can reach this prefix, and here is the list of ASes on the way". The list doubles as loop protection.
  • Inside an AS, the IGP carries routes to the routers themselves (their loopback addresses), and iBGP rides on top of it carrying the external routes. iBGP routers don't pass iBGP-learned routes to other iBGP routers, so they need a full mesh of sessions or route reflectors (RFC 4456) that relay for everyone.

How BGP works

BGP version 4 (RFC 4271) is a conversation between two routers that an operator has configured as neighbors (also called peers). There is no discovery: both sides list each other's address and ASN.

  • The session is a single TCP connection to port 179. TCP handles delivery, so BGP only sends what changed.
  • On start-up the neighbors exchange their full tables (a full table from a transit provider is about a million IPv4 routes), then only incremental updates.
  • The session walks through states Idle → Connect → Active → OpenSent → OpenConfirm → Established. A session stuck in Active usually means TCP can't connect: a wrong address, a firewall, or the other side not configured yet.
MessageCarriesWhen
OPENversion, ASN, hold time, router ID, capabilities (32-bit ASNs, IPv6, route refresh…)once, to start the session
UPDATEwithdrawn prefixes, and/or new prefixes with their path attributeswhenever a route appears, changes or disappears
KEEPALIVEnothingabout every third of the hold time when there is nothing else to send
NOTIFICATIONan error codejust before closing the session on an error
ROUTE-REFRESHa request to resend routes (RFC 2918)after a policy change, so the table needn't be reset

The hold time is how long a router waits for any message before declaring the neighbor dead and throwing away all its routes. RFC 4271 suggests 90 seconds; Cisco and several others default to 180. Faster failure detection uses BFD alongside (see Building a network).

Withdrawing a route is not a separate message: it is an UPDATE with the prefix in its "withdrawn routes" field. Each router that loses the route tells its own neighbors, so the withdrawal ripples outward exactly like the announcement did.

AS 64500 AS 64501 645006450064500 AS 64503 64501 6450064501 64500 AS 64505 64503 64501 6450064503 64501 6450064503 64501 64500 AS 64502 645006450064500 AS 64504 64502 6450064502 64500 AS 64506 64504 64502 6450064504 64502 6450064504 64502 64500 203.0.113.0/24 origin 1. announce 2. withdraw UPDATE with a route UPDATE withdrawing it route installed

An announcement spreads one AS at a time, and so does its withdrawal

In reality each hop takes from milliseconds to tens of seconds: routers batch updates (the MRAI timer, minimum route advertisement interval) and process them in software. Withdrawals are often slower than announcements because routers first try every other path they have heard of (path hunting) before giving up.

Path attributes

Every route in an UPDATE carries path attributes, the facts a router uses to choose.

AttributeSet byMeaning
AS_PATHeach AS, prepending its own ASNthe ASes the route passed through, newest first: 64502 64500
NEXT_HOPthe sending routerthe address to forward packets to for this prefix
ORIGINthe originating AShow the route entered BGP: IGP, EGP or incomplete
LOCAL_PREFthe receiving AS, for itselfhigher is preferred; never leaves the AS; encodes business policy
MEDa neighbor AS"multi-exit discriminator": lower is preferred; a hint about which of several links to use
COMMUNITIESanyonetags such as 64500:120 that trigger policy elsewhere (RFC 1997); large communities 64500:1:120 (RFC 8092) fit 32-bit ASNs

Well-known communities include NO_EXPORT (65535:65281, don't pass outside the receiving AS) and BLACKHOLE (65535:666, RFC 7999: drop traffic to this prefix, used against DDoS attacks). Providers also publish their own: "tag your route X:3 and we prepend three times toward peers".

How a route spreads

AS 64500 AS 64501 AS 64503 AS 64502 AS 64510 origin 203.0.113.0/24 far AS 64500 64500 64501 64500 64502 64500 64503 64501 64500 best: 2 ASes traffic link down withdraw AS 64510's routes to 203.0.113.0/24 AS_PATH length status 64502 64500 2 ASes 64503 64501 64500 3 ASes only route compare compare best backup withdrawn best

1/6

AS 64500 originates 203.0.113.0/24 and sends an UPDATE to both neighbors. The AS_PATH holds just its own number: 64500.

  • Loop prevention: a router drops any route whose AS_PATH already contains its own ASN.
  • Prepending: an AS can add its own ASN several times (64500 64500 64500) to make a path look longer, so that other networks prefer a different link into it. It is a blunt tool: anyone who ranks routes by LOCAL_PREF first ignores it.
  • Path length is not distance. Three ASes can span three continents or one city. BGP knows nothing about latency or bandwidth unless operators encode it in policy.

Choosing the best path

When a router holds several routes for the same prefix, it runs the same comparison every time and stops at the first step that separates them. The order below is the common one (Cisco, Juniper, FRR, BIRD and others agree on the core; details vary by vendor):

#PreferWhy
1a reachable NEXT_HOPa route you can't forward to is useless
2highest weightCisco-only, local to one router; skip elsewhere
3highest LOCAL_PREFyour own business policy: customers before peers before providers
4routes this router originatedits own prefixes
5shortest AS_PATHfewer networks on the way
6lowest ORIGINIGP < EGP < incomplete
7lowest MEDcompared only between routes from the same neighbor AS, by default
8eBGP over iBGPleave the AS at the first chance
9lowest IGP cost to the NEXT_HOPthe nearest exit: "hot-potato" routing
10oldest eBGP routestability, on some implementations
11lowest router ID, then lowest neighbor addressa deterministic final tiebreak

Policy (step 3) almost always decides. Shortest path (step 5) is the first "distance" signal, and step 9 means each network hands traffic off as soon as it can, so the path from A to B and the path from B to A are often different (asymmetric routing).

Who pays whom

Links between ASes carry money as well as packets. There are three common relationships:

RelationshipMoneyWhat each side sends the other
customer → provider (transit)the customer pays, usually per Mbps or per portprovider: every route on the internet. Customer: its own routes and its customers'
settlement-free peeringnone; each pays for its own side of the linkeach sends only its own and its customers' routes
paid peeringone side pays, cheaper than transitas peering, for a fee
peer peer valley Tier 1 A Tier 1 B regional 1 regional 2 regional 3 access ISP company content customer pays provider (transit) peers swap their customers' traffic valid: up, across once, down leak: a customer as transit
Valid paths go up, cross at most one peering link, then go down

Those prices produce the export rules, also called "valley-free" routing (Lixin Gao, 2001): a network passes along routes only where someone pays it to carry the traffic.

Route learned fromExport to customersExport to peersExport to providers
a customeryesyesyes
a peeryesnono
a provideryesnono

So every valid path climbs zero or more customer → provider links, crosses at most one peering link, then descends. A path that goes down and up again, through a customer between two of its providers, is a valley: the customer would be carrying traffic between its providers for free, and its links would usually melt. That is what a route leak looks like.

  • Tier 1: a network that reaches every destination without buying transit, by peering with all the other Tier 1s. There is no official list; commonly named ones include Lumen (AS3356), Arelion (AS1299), NTT (AS2914), Cogent (AS174), GTT (AS3257) and Tata Communications (AS6453).
  • Tier 2: peers widely but still buys some transit. Tier 3 (or stub): buys all its connectivity.
  • The hierarchy has flattened: the largest content and cloud networks (Google, Meta, Netflix, Amazon, Microsoft) run their own global backbones and peer directly with access ISPs, so much of the traffic people use never touches a Tier 1.

Where networks meet

Interconnection is physical: two routers need a cable between them, so networks gather in the same buildings.

Place or linkWhat it isTypical use
colocation facility (carrier-neutral data center)a building where many networks rent racks and order cross-connects, a fiber run between two customers' rackswhere almost all interconnection happens
PNI (private network interconnect)dedicated ports and cross-connects between two networks' routers, often several 100 Gbit/s linkspairs that exchange a lot of traffic, e.g. a CDN and a big ISP
IXP (Internet Exchange Point)a shared Ethernet switch fabric, often spread over several facilities in a city; each member gets a port and an address on its peering LANpeering with hundreds of networks over one port
route servera BGP speaker at the IXP that relays routes between memberspeering with everyone who wants it in a single session
AS A AS B AS C AS D AS E Bilateral sessions 5 members: 10 sessions, n(n-1)/2 AS A AS B AS C AS D AS E route server Route server 5 members: 5 sessions, one each dashed = a BGP session; every session runs over the same IXP switch the route server only relays routes: traffic still goes member to member
A route server turns n(n-1)/2 sessions into n
  • A route server (RFC 7947) doesn't add its own ASN to the path or change the next hop, so routes look as if they came straight from the member, and traffic flows member to member across the switch; the route server never carries a data packet. BIRD and OpenBGPD are common implementations.
  • Many IXPs are run as non-profits or member associations, and members pay a port fee rather than for traffic. The largest, such as IX.br São Paulo and DE-CIX Frankfurt, each connect over a thousand networks.
  • PeeringDB (opens in a new tab) is the shared directory: which networks are present at which exchanges and facilities, their peering policies and contacts.

Anycast

Normally one prefix has one origin. Anycast announces the same prefix from many sites at once. Every router simply picks its best route as usual, so each user's packets end up at whichever site is closest in BGP terms: usually, though not always, the nearest geographically.

longer path Paris London New York Toronto Tokyo Sydney Frankfurt 192.0.2.0/24 Ashburn 192.0.2.0/24 Singapore 192.0.2.0/24 every user sends to the same address, 192.0.2.1 one prefix, announced from three sites: each user reaches the nearest

Same address everywhere; BGP delivers each user to the nearest copy
  • The DNS root servers are anycast: 13 named identities (a.root-servers.net to m.root-servers.net), run by 12 operators, served from about 2,000 instances (root-servers.org (opens in a new tab)). So are public resolvers such as 1.1.1.1 and 8.8.8.8, and most CDNs.
  • Failover is automatic: a site that withdraws its route stops attracting traffic, and its users move to the next-best site within seconds to minutes.
  • A DDoS attack gets split across every site instead of landing on one.
  • Routes are stable enough that TCP works over anycast, but a route change mid-connection can send packets to a different site that knows nothing about the connection, which resets it. CDNs keep their announcements steady and mitigate the rest.
  • Load balancing inside a site is a separate layer; see System design.

When routing goes wrong

BGP trusts what neighbors say. Two kinds of mistakes (or attacks) follow:

  • A hijack: an AS announces a prefix it doesn't hold, or a more specific part of it. Longest-prefix match then sends traffic to the wrong place.
  • A route leak (RFC 7908): a route is passed on beyond where it should go, typically a customer re-announcing one provider's routes to another provider: the valley in the diagram above.
YouTube AS36561 announces 208.65.152.0/22 Pakistan Telecom AS17557 announces 208.65.153.0/24 a router anywhere prefix via 208.65.152.0/22 AS36561 208.65.153.0/24 AS17557 BGP routes traffic for 208.65.153.x both prefixes contain 208.65.153.x; the longest match (/24) wins
A more-specific announcement wins everywhere it is accepted
Date (UTC)IncidentWhat happened
2008-02-24Pakistan Telecom hijacks YouTubeOrdered to block YouTube nationally, Pakistan Telecom (AS17557) announced 208.65.153.0/24, more specific than YouTube's 208.65.152.0/22. Its upstream PCCW (AS3491) passed it on and most of the internet sent YouTube traffic to Pakistan. YouTube announced the /24 and then two /25s to win traffic back; PCCW withdrew the bad route about two hours after it started (18:47 to 21:01, per RIPE NCC)
2019-06-24Verizon passes on a leakDQE Communications (AS33154) ran a "BGP optimizer" that split prefixes into more-specifics for internal use. They reached its customer Allegheny Technologies (AS396531), which announced them to its other provider, Verizon (AS701), which accepted and propagated them. Traffic for Amazon, Linode, Cloudflare and others was pulled through small networks; Cloudflare saw about 15% of its global traffic lost at the worst point
2021-10-04Facebook withdraws itselfNot a leak: a maintenance command meant to measure backbone capacity disconnected all of Facebook's data centers, and a bug in the audit tool failed to stop it. Its DNS servers are built to withdraw their BGP routes when they can't reach the data centers, so they did. With the prefixes of its authoritative DNS servers gone, facebook.com, Instagram and WhatsApp didn't resolve for about 5.5 hours (roughly 15:50 to 21:20, per Cloudflare), and engineers had to go on site because remote access was down too

Defenses

DefenseWhat it doesLimits
customer filters from the IRRbuild a prefix list for each customer from Internet Routing Registry objects (route, as-set), e.g. with bgpq4IRR data is self-published and often stale
max-prefix limitstear down a session that suddenly sends far more routes than usualcatches big leaks, not a single bad prefix
RPKI and ROVthe RIRs certify who holds which addresses; holders sign ROAs (route origin authorizations: prefix, maximum length, allowed origin ASN). Routers check every route (route origin validation, RFC 6811) and drop invalid oneschecks only the origin AS, so a forged path ending in the right ASN passes
ASPAan RPKI object listing an AS's providers, so routers can spot valleys and some forged pathsIETF drafts, not yet an RFC as of November 2026; early support in some validators and routers
BGPsec (RFC 8205)signs every hop of the pathstandardized in 2017 but essentially undeployed
MANRSa community norm, now supported by the Global Cyber Alliance: filter, block spoofed source addresses, keep contacts current, publish your routing policyvoluntary
  • ROV results are valid (a ROA matches), invalid (a ROA exists but the origin or length is wrong) or not found (no ROA; accepted as before). Validators such as Routinator, rpki-client and FORT feed the results to routers.
  • Coverage has grown fast: by 2026 roughly two-thirds of routed prefixes have a ROA, depending on how you measure. A ROA for 208.65.152.0/22 with maximum length 22 would make the 2008 /24 invalid wherever ROV is on; Cloudflare noted the same of the 2019 leaked more-specifics.
  • Keep ROAs tight: a maximum length longer than you actually announce lets a hijacker announce a more-specific with your ASN as origin.

The physical internet

BGP draws a map of agreements; under it is glass. Every AS adjacency is a real cable between two routers, and nearly all long-distance traffic travels as light in optical fiber.

  • Submarine cables cross oceans: TeleGeography tracks more than 600 active and planned systems and over 1.5 million km in service (2026). Each lands at a cable landing station on the coast, then runs inland to data centers.
  • Terrestrial backbones run along railways, highways and pipelines between a few dozen hub cities, where colocation facilities and IXPs cluster.
  • Light in fiber covers about 200 km per millisecond, so distance sets a floor on latency that no protocol removes.
  • Cables get cut, mostly by ship anchors and fishing gear. BGP reroutes around a cut within seconds to minutes, but the detour can add tens of milliseconds and crowd the remaining cables until a repair ship fixes the break.

How fiber, DWDM and submarine systems work is in Wired networks; the full trip of one packet across all of this is in A packet's journey.

Try it

Look up who announces an address, what an AS publishes, and whether a route is RPKI-valid. Network commands for your own machine are in Sysadmin.

# Which AS announces this address? (Team Cymru, bgp.tools)
whois -h whois.cymru.com " -v 1.1.1.1"
whois -h bgp.tools " -v 8.8.8.8"
 
# Registry record for an AS, and its IRR route objects
whois AS13335
whois -h whois.radb.net -- '-i origin AS13335' | grep ^route
 
# Is this origin allowed to announce this prefix? (RPKI)
curl -s "https://stat.ripe.net/data/rpki-validation/\
data.json?resource=13335&prefix=1.1.1.0/24" \
  | jq -r .data.status
# valid
 
# Which exchanges does a network peer at? (PeeringDB)
curl -s "https://www.peeringdb.com/api/netixlan?asn=13335" \
  | jq '.data | length'
 
# The AS of every hop on the way
traceroute -A example.com
mtr -rwz -c 20 example.com
ToolGood for
bgp.tools (opens in a new tab)an AS's prefixes, upstreams, peers and IXPs, with live updates
Hurricane Electric BGP Toolkit (opens in a new tab)prefixes, peers and IRR data per AS; a looking glass
RIPEstat (opens in a new tab)routing history, visibility and RPKI status of any prefix, with a JSON API
PeeringDB (opens in a new tab)who is present at which IXP and facility
looking glassesrun show ip bgp on someone else's router to see a prefix from their side
Cloudflare Radar (opens in a new tab)detected route leaks, hijacks and outages
CIDR Report (opens in a new tab)table size and the networks that aggregate worst

References