What Is BGP (Border Gateway Protocol)? How Autonomous Systems Route the Internet

Border Gateway Protocol (BGP) is the routing protocol that autonomous systems use to exchange IP prefix reachability across the internet. Every packet that crosses an AS boundary was routed by a BGP best-path decision, and every anycast DNS platform steers your queries to the nearest point of presence with the same protocol.

What Is Border Gateway Protocol (BGP) and How Does Inter-Domain Routing Work?

Border Gateway Protocol (BGP) is a path-vector Exterior Gateway Protocol (EGP) that autonomous systems use to announce IP prefix reachability and exchange routing policy over TCP port 179. Every BGP route carries an AS_PATH attribute listing every ASN the prefix has traversed, which serves both as a loop-prevention mechanism and as a routing metric (shorter paths are generally preferred).

AttributeValue
Protocol ClassificationPath-Vector Exterior Gateway Protocol (EGP)
Transport LayerTCP port 179 (reliable, ordered delivery)
Routing Unit (NLRI)IPv4 and IPv6 CIDR prefixes
Network Identifier16-bit or 32-bit Autonomous System Number (ASN)
Session ModeseBGP (between different ASNs) and iBGP (within one ASN)
Loop DetectionAS_PATH attribute (a router rejects its own ASN in the path)
Core StandardsRFC 4271 (BGP-4), RFC 4760 (Multiprotocol Extensions)

The diagram below shows how a customer prefix travels outward through provider networks, with each AS prepending its own number to the AS_PATH attribute.

eBGP sessions over TCP port 179 · UPDATE messages carry prefixes outward from the origin AS64496 Stub (origin of 203.0.113.0/24) AS64497 Transit ISP AS64498 Tier-1 backbone UPDATE 203.0.113.0/24 AS_PATH: 64496 UPDATE 203.0.113.0/24 AS_PATH: 64496 64497 traffic follows the best AS_PATH in reverse each AS prepends its own ASN to AS_PATH · a router rejects any path that already contains its own ASN shorter AS_PATH wins best-path selection unless LOCAL_PREF overrides it
Figure: an eBGP announcement travels from the origin AS through a transit ISP to a Tier-1 backbone, with the AS_PATH growing at every hop.

BGP sits at the top of the routing stack conceptually as well as topologically. An Autonomous System Number identifies who is speaking, the prefix (which you can decompose with the CIDR calculator) identifies what is being announced, and the AS_PATH records who relayed the announcement - and the live trace tool further down this page lets you read all three for any address.

How the BGP Session Lifecycle and Best-Path Selection Algorithm Work

BGP session establishment and route exchange proceed through 4 phases:

  1. Establish TCP connection and exchange OPEN messages: Two routers form a TCP connection on port 179 and exchange OPEN messages carrying their ASN, BGP identifier (router ID), and capability flags (such as IPv6 or 4-byte ASN support).
  2. Advertise NLRI prefixes via UPDATE messages: Each router announces the IP prefixes it can reach, carrying path attributes (AS_PATH, NEXT_HOP, LOCAL_PREF, MED, origin code) that downstream routers use for best-path selection.
  3. Evaluate best-path attributes: When multiple routes to the same prefix exist, the router runs a deterministic best-path algorithm comparing LOCAL_PREF, AS_PATH length, origin code, MED, eBGP-vs-iBGP preference, IGP metric, and router ID.
  4. Maintain liveness via KEEP-ALIVE and handle NOTIFICATION: Periodic KEEP-ALIVE messages confirm the session is healthy. A NOTIFICATION message immediately tears down the session and withdraws all routes learned from that peer.

The table below defines the BGP best-path tie-breaking order used by Cisco, Juniper, and other major router vendors:

PriorityAttributePreference Rule
1Highest LOCAL_PREFHigher administrative preference wins (set via route policy)
2Shortest AS_PATH lengthFewer AS hops in the path is preferred (shorter network distance)
3Lowest origin codeIGP (i) is preferred over EGP (e), which is preferred over Incomplete (?)
4Lowest Multi-Exit Discriminator (MED)Lower MED tells the neighboring AS which entry point to prefer
5eBGP preferred over iBGPExternal routes are preferred over internal routes at equal precedence
6Lowest IGP metric to NEXT_HOPCloser next-hop router in the interior topology is preferred
7Oldest external route / lowest router IDStability tie-breaker: oldest eBGP route wins, then lowest router ID

Two properties of this algorithm explain most real-world routing behavior. First, LOCAL_PREF and AS_PATH are the only knobs a network genuinely uses day to day: traffic engineering in BGP means making your own paths longer (AS_PATH prepending) or your preferred paths administratively favored. Second, the algorithm is deterministic, which is exactly why anycast works at all: every router on earth independently computes a route to the nearest announcing site.

eBGP vs iBGP vs Interior Gateway Protocols (OSPF, IS-IS, and EIGRP)

The table below contrasts the three routing domains:

AttributeeBGPiBGPIGP (OSPF / IS-IS)
ScopeBetween different ASNsWithin one ASNWithin one routing domain (typically inside one ASN)
Primary purposeExchange internet prefixes with peers and upstreamsDistribute external routes to all edge routers inside the ASCompute shortest paths for internal infrastructure links
TransportTCP port 179TCP port 179IP protocol 89 (OSPF) or CLNS (IS-IS)
Loop preventionAS_PATH prependingSplit horizon (no re-advertisement to iBGP peers)Link-state database with Dijkstra SPF

The division of labor is strict: the IGP knows only internal links and never carries full internet routes, iBGP spreads everything the edge routers learn to every other router in the AS, and eBGP decides what the outside world hears from you. A route that fails at any layer stops propagating, which is why an iBGP split-brain can silently isolate an entire ASN from a prefix while eBGP sessions on the edge stay perfectly healthy.

The BGP RFC Timeline: From RFC 1105 to RFC 9234

BGP is one of the oldest protocols still running the internet core, and its specification history explains several quirks that survive in production networks today. The table below lists the significant milestones:

YearRFCWhat It Changed
1989RFC 1105 (BGP-1)First BGP specification, replacing EGP (Exterior Gateway Protocol, RFC 904)
1990RFC 1163 (BGP-2)Introduced path attributes, including AS_PATH and NEXT_HOP
1991RFC 1267 (BGP-3)Added collision detection and refined the UPDATE message format
1995RFC 1771 (BGP-4)CIDR support: classless prefixes replaced the classful network model
2006RFC 4271 (current)The authoritative BGP-4 standard in force today
2012RFC 67934-byte (32-bit) ASNs, with AS_TRANS (AS23456) backward compatibility
2017RFC 8205 (BGPsec)Per-hop cryptographic signing of the AS_PATH
2022RFC 9234Route Leak Prevention: BGP Role and Only-To-Customer (OTC) attribute

The timeline explains the quirks: AS_PATH exists because of BGP-2 (1990), CIDR support arrived only with BGP-4 in 1995 (which is why the 1993 RFC 1519 CIDR spec needed a routing protocol that could carry prefixes), and the 4-byte ASN transition left AS_TRANS artifacts you can still see in looking glasses today. The 2022 route-leak work shows the pattern continues: BGP security is being retrofitted one RFC at a time onto a 1989 protocol design.

How BGP Powers Anycast DNS (1.1.1.1 and 8.8.8.8) and Affects Web and Email Uptime

Anycast DNS providers such as Cloudflare (AS13335) and Google (AS15169) announce the exact same IPv4 /24 and IPv6 /48 prefixes from hundreds of global locations. BGP AS_PATH routing automatically sends each user's DNS query to the topologically nearest POP because the shortest AS_PATH leads to the closest announcing site. This is why 1.1.1.1 answers within milliseconds from almost anywhere on earth: BGP selected the nearest of 300+ cities without any DNS-level configuration.

The same mechanism affects web hosting: if your authoritative nameservers use anycast, a BGP route leak or hijack on your provider's prefixes can blackhole DNS resolution for your domain globally. Understanding BGP is therefore essential for DNS reliability, not just for network engineers. You can see which AS and prefix answers for any address with the IP lookup, and the DNS hijacking guide covers the resolution-layer attacks that pair with route-level ones.

BGP Security Threats (Route Leaks and Hijacks) and Command-Line Diagnostics

The table below defines the four major BGP security failure states and their defenses:

Failure StateHow It HappensDefense Mechanism
Sub-prefix BGP hijackAn attacker announces a more-specific prefix (e.g. /24 inside a /16) that attracts all traffic to that rangeRPKI ROA with MaxLength set to the exact announced prefix length
Origin AS spoofingA different AS announces the prefix, claiming to be the legitimate originRPKI ROA binding the prefix to the authorized origin ASN
Route leak (valley-free violation)An AS accidentally re-advertises learned routes to its own upstream, creating transit loopsIRR prefix filters, RFC 7908 route leak classification, peer lock
BGP session reset or prefix flapUnstable peering causes repeated withdrawals and re-announcementsMAX_PREFIX limits, route dampening, TCP-AO (RFC 5925) session protection

Every defense in that table except route dampening depends on knowing which origin should be announcing a prefix. That is exactly the guarantee RPKI and ROAs provide: cryptographically signed statements binding prefixes to origin ASNs that validating routers enforce globally within minutes.

# Verify the origin ASN for any IP via Team Cymru DNS
dig +short 1.1.1.1.origin.asn.cymru.com TXT

# Query the RADB internet routing database
whois -h whois.radb.net 1.1.1.0/24

# Trace the path and see AS numbers at each hop
mtr -z 1.1.1.1
traceroute -A 1.1.1.1

Trace a BGP origin live

Enter any IP address or AS number to see the originating ASN, announced prefix, and RPKI status, exactly as a BGP router would evaluate it. Run the full check in the ASN lookup tool.

Frequently Asked Questions

Is BGP the only routing protocol that connects autonomous systems?+

Yes, BGP is the only routing protocol used to exchange routing information between different autonomous systems on the public internet. Interior gateway protocols (OSPF, IS-IS, EIGRP) handle routing within a single AS, but when traffic must cross an AS boundary, BGP is the universal protocol that both peers speak over TCP port 179.

Does BGP use TCP or UDP?+

BGP uses TCP on port 179. Every BGP session is a long-lived TCP connection between two routing peers, which provides reliable delivery, ordering, and retransmission without requiring BGP itself to implement those functions. This is unlike OSPF or EIGRP, which send packets directly over IP.

Can BGP be hijacked, and how does RPKI prevent it?+

Yes, BGP hijacks occur when an AS announces a prefix it does not own, either intentionally or by misconfiguration. RPKI (Resource Public Key Infrastructure) prevents origin hijacks by using cryptographically signed Route Origin Authorizations (ROAs) that bind each prefix to its authorized originating ASN. Routers that validate RPKI reject announcements that fail the ROA check.

Why does anycast DNS depend on BGP?+

Anycast DNS providers announce the same IP prefix from hundreds of global locations. BGP is the protocol that automatically routes each user to the topologically nearest announcing location, because the AS_PATH to the nearest POP is shortest. Without BGP, anycast load distribution would not work, and every DNS query would travel to a single data center.

Last verified: 2026-11-08