BGP (Border Gateway Protocol)

Networking

The routing protocol that makes the internet work. BGP allows autonomous systems to exchange routing information and determines how traffic flows between networks. CDNs use BGP for Anycast and traffic engineering.

Updated Apr 3, 2026

Full Explanation

BGP is the routing protocol that glues the entire internet together. It is how autonomous systems (ASes) tell each other which IP ranges they can reach. Every ISP, cloud provider, and CDN uses BGP to announce their networks and learn about paths to other networks. Without BGP, routers would have no idea how to forward packets between organizations.

For CDNs, BGP is essential for anycast routing. A CDN like Cloudflare advertises the same IP prefix (say 104.16.0.0/13) from every single PoP worldwide. When a user sends a packet to that IP, BGP routing naturally directs it to the closest PoP based on AS path length, network topology, and peering relationships. This is what makes anycast work. No DNS tricks needed for the routing layer.

BGP path selection follows a set of rules. It considers local preference (operator-defined priority), AS path length (fewer hops usually wins), origin type, MED (multi-exit discriminator), and various tie-breakers. Network engineers at CDNs use these knobs to do traffic engineering, steering traffic to less-congested PoPs or away from failing infrastructure.

BGP has real security risks. A BGP leak happens when an AS accidentally announces routes it should not, pulling traffic through the wrong network. A BGP hijack is the malicious version of this. These incidents have caused major outages and even redirected traffic through hostile networks. RPKI (Resource Public Key Infrastructure) is being adopted to cryptographically validate route announcements, but adoption is still not universal. Also worth noting: BGP convergence (the time for all routers to agree on new routes) can take minutes, which is why CDN failover after a PoP goes down is not always instant.

Examples

Here is a simplified view of what BGP announcements look like and how you can inspect them:

# View BGP routes for a prefix using a looking glass
# Many networks provide public looking glass servers

# Check BGP route info via RIPE Stat
curl -s "https://stat.ripe.net/data/looking-glass/data.json?resource=104.16.0.0/13" | python3 -m json.tool

# Use bgp.he.net to look up AS paths
# Example: AS path to Cloudflare (AS13335)
# Your ISP (AS1234) -> Transit (AS5678) -> Cloudflare (AS13335)

# Check if RPKI validation is in place
curl -s "https://stat.ripe.net/data/rpki-validation/data.json?resource=AS13335&prefix=104.16.0.0/13"

In a CDN anycast setup, the same prefix is announced from dozens of PoPs. BGP picks the "closest" one based on the AS path and peering topology, not physical distance. A user in Amsterdam might route to a Frankfurt PoP if the network path is shorter, even though there is a PoP in Amsterdam.

Video Explanation

Frequently Asked Questions

The routing protocol that makes the internet work. BGP allows autonomous systems to exchange routing information and determines how traffic flows between networks. CDNs use BGP for Anycast and traffic engineering.

Here is a simplified view of what BGP announcements look like and how you can inspect them:

# View BGP routes for a prefix using a looking glass
# Many networks provide public looking glass servers

# Check BGP route info via RIPE Stat
curl -s "https://stat.ripe.net/data/looking-glass/data.json?resource=104.16.0.0/13" | python3 -m json.tool

# Use bgp.he.net to look up AS paths
# Example: AS path to Cloudflare (AS13335)
# Your ISP (AS1234) -> Transit (AS5678) -> Cloudflare (AS13335)

# Check if RPKI validation is in place
curl -s "https://stat.ripe.net/data/rpki-validation/data.json?resource=AS13335&prefix=104.16.0.0/13"

In a CDN anycast setup, the same prefix is announced from dozens of PoPs. BGP picks the "closest" one based on the AS path and peering topology, not physical distance. A user in Amsterdam might route to a Frankfurt PoP if the network path is shorter, even though there is a PoP in Amsterdam.