BGP Deep Dive: How the Internet Routes Traffic

BGP is the protocol that holds the internet together. Every packet that crosses network boundaries is guided by BGP's decisions.

Run a real BGP peering session

Free interactive lab. No signup. Runs in your browser.

Quick Summary

What Is BGP?

The internet is not a single network -- it is a network of networks, each operated independently by different organizations. These organizations include internet service providers (ISPs), large enterprises, content delivery networks, cloud providers, and universities. Each independently operated network is called an Autonomous System (AS) and is identified by a unique number (ASN). Comcast might be AS7922, Google is AS15169, and Amazon is AS16509.

Border Gateway Protocol (BGP) is the routing protocol that allows these autonomous systems to communicate with each other. When AS15169 (Google) wants the rest of the internet to know how to reach its IP addresses, it uses BGP to advertise those prefixes to its neighbors. Those neighbors then re-advertise the routes to their neighbors, and so on, until every AS on the internet knows at least one path to reach Google's network.

BGP is fundamentally different from interior routing protocols like OSPF or EIGRP. While those protocols find the shortest path within a single network, BGP operates between networks and makes routing decisions based on policy rather than just distance. An ISP might prefer to route traffic through a paid transit provider even if a shorter path exists through a peering partner, because business agreements dictate routing preferences. This policy-based nature makes BGP both powerful and complex.

Interactive: BGP Route Advertisement

Click on an AS to originate a route advertisement. Watch the prefix propagate through eBGP sessions as each AS prepends its own ASN to the AS-path.

Internet Topology (4 Autonomous Systems)

AS 100 ISP Alpha 10.100.0.0/16 Click to advertise AS 200 ISP Beta 10.200.0.0/16 Click to advertise AS 300 Enterprise 10.300.0.0/16 Click to advertise AS 400 CDN Provider 10.400.0.0/16 Click to advertise eBGP eBGP eBGP eBGP
BGP sessions established. Click on any AS to originate a route advertisement...

How BGP Works

1

BGP Sessions and Peering

BGP routers form explicit TCP connections (port 179) with their peers. Unlike OSPF which discovers neighbors automatically, BGP peers must be manually configured. There are two types: eBGP (External BGP) runs between different autonomous systems, and iBGP (Internal BGP) runs between routers within the same AS. eBGP peers are typically directly connected, while iBGP peers can be anywhere in the AS and often peer via loopback addresses for resilience.

2

Route Advertisement and AS-Path

When an AS wants the internet to know about its IP prefixes, it originates a BGP UPDATE message. As this update passes through each AS on the way to its neighbors, the transit AS prepends its own ASN to the AS-path attribute. This creates a chain like "AS100 AS200 AS300" that records the exact sequence of networks the route advertisement has traversed. The AS-path serves dual purposes: it is used for loop prevention (a router rejects any route that already contains its own ASN) and for path selection (shorter AS-paths are generally preferred).

3

BGP Best Path Selection

When a BGP router receives multiple routes to the same prefix, it runs a complex decision algorithm to select the best one. The algorithm checks (in order): highest Local Preference, shortest AS-path length, lowest origin type (IGP > EGP > Incomplete), lowest MED (Multi-Exit Discriminator), prefer eBGP over iBGP, lowest IGP cost to the next hop, and finally lowest Router ID as a tiebreaker. This ordered evaluation gives operators many knobs to control traffic flow.

4

BGP Policies and Filtering

Unlike IGP protocols that aim to distribute all routes everywhere, BGP is heavily filtered. ISPs use route maps, prefix lists, and community attributes to control which routes they accept, which they advertise, and how they are preferred. A transit provider might accept a customer's /24 prefixes but filter anything longer than /24 to prevent table bloat. Communities (like "do not export to peers") allow one AS to influence routing decisions in a neighboring AS without direct configuration access.

eBGP vs. iBGP

External BGP (eBGP) and Internal BGP (iBGP) serve different purposes and have different rules. eBGP sessions run between routers in different autonomous systems. When a route is received via eBGP, the receiving router modifies the AS-path by prepending its own ASN before re-advertising the route to other eBGP and iBGP peers. The TTL for eBGP packets is set to 1 by default, meaning peers must be directly connected (unless multi-hop eBGP is configured).

iBGP sessions run between routers within the same AS. A critical rule of iBGP is the split-horizon rule: routes learned from one iBGP peer are not re-advertised to other iBGP peers. This prevents routing loops within the AS, but it means every iBGP router must peer with every other iBGP router (a full mesh). In large networks, this full mesh requirement is addressed using route reflectors or confederations to scale iBGP without requiring n*(n-1)/2 sessions.

Real-World BGP

🌐

Internet Backbone

The global internet routing table contains over 950,000 IPv4 prefixes, all exchanged via BGP. Tier 1 ISPs peer with each other at internet exchange points (IXPs), forming the backbone that connects all networks worldwide.

💰

Multi-Homing

Enterprises connect to multiple ISPs for redundancy. BGP allows them to advertise their prefixes through both ISPs and control inbound traffic using AS-path prepending or MED values. If one ISP fails, traffic reroutes automatically.

CDN Anycast

Content delivery networks like Cloudflare advertise the same IP prefix from hundreds of locations worldwide. BGP naturally routes each user to the closest server, providing low-latency content delivery without any client configuration.

BGP Security Challenges

BGP Hijacking

Any AS can announce any prefix. A misconfigured or malicious AS can advertise someone else's IP space, redirecting their traffic. RPKI (Resource Public Key Infrastructure) helps by cryptographically validating route origins, but adoption is still growing.

Route Leaks

A route leak occurs when an AS re-advertises routes it should not -- for example, a customer advertising transit routes learned from one ISP to another ISP. This can cause traffic to take suboptimal paths or overwhelm small networks.

Convergence Delays

BGP converges slowly compared to IGPs. When a route is withdrawn, the withdrawal must propagate through every AS. Path exploration during convergence can cause temporary routing loops and packet loss lasting minutes.

Frequently asked questions about BGP

What does BGP stand for?

BGP stands for Border Gateway Protocol. It is the path-vector routing protocol that ties the public internet together by letting independently-operated networks (autonomous systems) advertise reachability to each other.

How does BGP work?

BGP routers form TCP sessions with their neighbors and exchange UPDATE messages containing prefixes plus path attributes like AS_PATH and NEXT_HOP. The best-path algorithm then picks one route per prefix based on local preference, shortest AS path, and several tiebreakers.

What is the difference between iBGP and eBGP?

eBGP runs between routers in different autonomous systems and is how networks exchange routes with the rest of the internet. iBGP runs between routers inside the same AS and is used to distribute external routes throughout the network without modifying the AS path.

Is BGP secure?

BGP itself has no built-in cryptographic trust. A misconfigured or malicious AS can announce prefixes it does not own — a route hijack. Operators mitigate this with prefix filters, RPKI Route Origin Validation, and increasingly BGPsec, but BGP security is still an active concern.

Why is BGP slow to converge?

BGP was designed for stability rather than speed. It uses timers, route dampening, and incremental updates that can take seconds to minutes to fully propagate a change across the internet. This is acceptable because BGP runs the inter-domain layer where churn is expensive.

Ready to try BGP?

You just learned how BGP peering, the best-path algorithm, and AS paths work. Now run a real eBGP session: set each router's ASN and neighbor, press Go Live so BIRD forms the session, and check with birdc show route which prefixes crossed and which path was chosen.

Launch the BGP lab →