BGP Routing: How the Internet Finds Its Way

· Priya Sharma · 9 min read

BGP (Border Gateway Protocol) is the routing protocol that holds the internet together — the system that determines how data packets find their way across the global network of 75,000+ autonomous systems. Often called "the postal service of the internet," BGP enables every ISP, cloud provider, and CDN to exchange routing information and deliver traffic to its destination. For CDN providers, BGP is especially critical because it powers anycast — the technique that directs users to the nearest edge server. Understanding BGP is essential for grasping how CDNs route content globally.

What Is the History of BGP?

BGP's history reflects the internet's evolution from a research network to a global commercial infrastructure:

Today, the global BGP routing table contains over 1 million IPv4 prefixes and 200,000+ IPv6 prefixes, managed across 75,000+ autonomous systems.

BGP Path Selection — BGP routers evaluate multiple paths across autonomous systems and select the be BGP Path Selection — How routers choose the best path across autonomous systems BGP Path Selection Across Autonomous Systems AS 64501 Your ISP AS 13335 Cloudflare AS 3356 Lumen AS 16509 Amazon AS 20940 Akamai Destination Website Path 1 Path 2 BGP selects shortest AS-PATH: Path 1 (2 hops) preferred over Path 2 (3 hops) CDNs manipulate BGP to advertise shortest paths from every edge location
Figure 1: BGP Path Selection — BGP routers evaluate multiple paths across autonomous systems and select the best route based on AS-PATH length, local preference, and other attributes

How Does BGP Work?

BGP operates as a "path vector" routing protocol, where each network (Autonomous System, or AS) exchanges information about which IP address ranges (prefixes) it can reach and the path of ASes needed to get there:

Performance Comparison: Edge vs Origin Processing
Metric Edge Processing Origin Processing Improvement
Latency (p50)8–15 ms120–300 ms15–20x faster
Cache Hit Ratio85–95%N/AReduces origin load
TLS Handshake1–5 ms (nearby PoP)50–150 ms10–30x faster
Bandwidth Cost$0.01–0.04/GB$0.05–0.12/GB3–5x cheaper
Availability99.99% (multi-PoP)99.9% (single DC)10x fewer outages
  1. Peering Session Establishment: Two BGP routers (called "peers" or "neighbors") establish a TCP connection on port 179. They exchange OPEN messages containing their AS number, BGP version, and capabilities.
  2. Route Exchange: Peers exchange UPDATE messages containing route announcements (new or changed routes) and withdrawals (removed routes). Each announcement includes the prefix (e.g., 104.26.0.0/20), the AS-PATH (the sequence of ASes the route traverses), and various attributes (next-hop, community tags, MED).
  3. Route Selection: When a router receives multiple paths to the same destination, it applies a decision process (in order of priority): highest local preference → shortest AS-PATH → lowest origin type → lowest MED → prefer eBGP over iBGP → lowest IGP metric to next-hop → lowest router ID.
  4. Route Propagation: Selected best routes are propagated to other BGP peers, with the router's own AS prepended to the AS-PATH (preventing routing loops).

What Are the Most Notable BGP Incidents?

BGP was designed without built-in authentication, making it vulnerable to route hijacking — when an AS incorrectly announces someone else's IP prefixes:

How Do CDNs Use BGP for Anycast?

CDN providers use BGP in a specialized way called anycast: they announce the same IP prefix from multiple geographic locations simultaneously. When a user sends a request to an anycast IP address, BGP routing automatically directs the packet to the nearest (in BGP terms, shortest AS-PATH) location:

How Is BGP Being Secured?

Several technologies are being deployed to address BGP's security weaknesses:

CDN Anycast via BGP — All CDN PoPs announce the same IP prefix; BGP routing directs each user to the CDN Anycast via BGP — Same IP announced from multiple global locations CDN Anycast: Same IP, Multiple Locations All PoPs announce 104.26.10.0/24 via BGP — user reaches nearest one 104.26.10.0/24 (Anycast) PoP Tokyo BGP: 104.26.10.0/24 PoP London BGP: 104.26.10.0/24 PoP New York BGP: 104.26.10.0/24 PoP Sydney BGP: 104.26.10.0/24 User in Japan → Tokyo User in France → London User in USA → New York User in NZ → Sydney
Figure 2: CDN Anycast via BGP — All CDN PoPs announce the same IP prefix; BGP routing directs each user to the geographically nearest location

External References

References & Standards: RFC 7234 · Cloudflare documentation