The Border Gateway Protocol (BGP) doesn’t actually route traffic; it advertises paths to traffic, and routers decide which path is best.

Let’s see BGP in action. Imagine two independent networks, AS1 (Autonomous System 1) and AS2 (Autonomous System 2), wanting to exchange routes.

AS1 (192.168.1.0/24) <---- BGP Peering ----> AS2 (10.0.0.0/24)

AS1 will tell AS2, "Hey, to reach my network 192.168.1.0/24, you can go through me." AS2 will reciprocate, "To reach my network 10.0.0.0/24, you can go through me."

On a router in AS1 (let’s call it R1) and a router in AS2 (R2), this might look like a basic BGP configuration:

R1 (in AS1):

router bgp 65001
 neighbor 10.0.0.2 remote-as 65002
 !
 address-family ipv4 unicast
  network 192.168.1.0/24
 exit-

R2 (in AS2):

router bgp 65002
 neighbor 192.168.1.2 remote-as 65001
 !
 address-family ipv4 unicast
  network 10.0.0.0/24
 exit-

After this configuration, R1 and R2 establish a BGP session. R1 will send an UPDATE message to R2 advertising the 192.168.1.0/24 network. This UPDATE message contains the network prefix and path attributes. The most crucial attribute here is the AS_PATH, which would initially be 65001. R2, upon receiving this, adds its own AS number to the path, making it 65001 65002, and advertises it to other BGP peers it might have.

This mechanism allows networks to announce reachability. When a router receives multiple advertisements for the same prefix, it applies a path selection algorithm. The most common scenario is that it prefers the shortest AS_PATH. If AS1 and AS2 are directly connected and peer with each other, their AS numbers will be added to the path. If AS1 also peers with AS3, and AS3 peers with AS2, AS2 might receive two paths to 192.168.1.0/24: 65001 (directly from AS1) and 65001 65003 (from AS3). BGP would choose the direct path.

The problem BGP solves is the need for a scalable routing protocol between different administrative domains (Autonomous Systems). The Internet is a collection of these ASes, each managed by an ISP, a large company, or a university. BGP is the glue that allows them to exchange information about which IP address blocks they can reach, enabling global internet connectivity. It’s not about finding the absolute shortest physical path, but rather the most policy-preferred path, which often correlates with the shortest AS path but can be influenced by many other attributes like LOCAL_PREF, MED (Multi-Exit Discriminator), and community tags.

BGP doesn’t store full routing tables like OSPF or IS-IS do for internal routing. Instead, it focuses on exchanging reachability information for IP prefixes. When a router receives an UPDATE message, it checks if the advertised path contains its own AS number (to prevent routing loops). If it’s a valid path, it updates its BGP table. Then, it runs the BGP best path selection algorithm to determine the best path to install in its IP routing table. This installed path is what the router actually uses to forward packets.

The magic behind BGP’s scalability isn’t just the AS path length; it’s the aggregation of routes. ISPs don’t advertise every single customer IP address. Instead, they aggregate them into larger blocks. For instance, instead of advertising 203.0.113.0/24, 203.0.113.1/24, etc., they’ll advertise 203.0.113.0/20. This drastically reduces the number of routes BGP routers need to store and process, making the global routing table manageable.

A common misconception is that BGP is slow to converge. While it can be slower than interior gateway protocols (IGPs) like OSPF, its convergence time is largely dependent on the network topology, peering relationships, and timer configurations (like keepalive and holdtime intervals). For example, if a BGP session between two routers drops, it might take up to 180 seconds (the default holdtime) for the session to be declared down, and then further time for alternative paths to be selected and propagated. However, mechanisms like BGP graceful restart and route refresh help mitigate convergence delays.

BGP is fundamentally a distributed policy enforcement mechanism. An AS can influence how its traffic enters and leaves its network by manipulating path attributes. For instance, an ISP might set a higher LOCAL_PREF on routes learned from a preferred upstream provider, ensuring that outbound traffic prefers that provider. Conversely, they might set a lower MED on routes advertised to a peering partner to encourage traffic to enter their network via that peer.

The next concept you’ll run into is the complexity of BGP path attributes and how they are manipulated to implement routing policies.

Want structured learning?

Take the full Computer Networking course →