Border Gateway Protocol (BGP)

In this tutorial, you will learn the basic concepts of BGP routing algorithms. After reading this tutorial, you will understand the working of BGP, the routing policies involved, and how BGP chooses a path.


  1. Border Gateway Protocol (BGP)
  2. Routing Policies between Autonomous Systems
  3. Propagation of BGP Route Advertisements
  4. How BGP Choose Route?

Border Gateway Protocol (BGP)

Border Gateway Protocol (BGP) is a standardized exterior gateway protocol designed to exchange routing and reachability information among autonomous systems (ASes) on the Internet. In short, BGP is an inter-domain routing protocol used between autonomous systems.

  • The main purpose of the intradomain routing protocol is to efficiently transfer packets from sender to receiver. It doesn’t care about policies. In contrast, interdomain routing protocols have policies.
  • BGP is an interdomain routing protocol, designed to allow a variety of routing policies to be implemented between autonomous systems.
  • The BGP has policies that involve political, security, or economic considerations. For example, traffic from commercial networks does not go through educational networks.
  • Routing policy is decided based on the type of traffic flow between ASes (Autonomous systems).
  • The customer and the provider have an ISP (Internet Service Provider). The customer ISP pays the provider ISP to send packets to another destination on the Internet and receive packets from the other destination. In this, customer ISP purchases the transit service from the provider ISP.

Routing Policies between Autonomous Systems

As we discussed transit service in the above section. Let us understand transit service with an example, which describes the policies between autonomous systems.


The diagram below explains the routing policies between autonomous systems.

Routing Policies between Autonomous Systems
  • As shown in the figure, there are four autonomous systems (ASes). AS1 provides transit service, and AS2, AS3, and AS4 are customers, they buy it.
  • PC-1 wants to communicate with PC-3. When PC-1 sends the packet to PC-2, the packet first travels from AS2 to AS1 and from AS1 to AS4.
  • AS4 advertises that PC-3 is the destination for its transit provider AS1 so that PC-1 can reach PC-3 through AS1.
  • Because all customers have purchased transit service from AS1, they can all communicate with each other over the Internet.
  • If AS2 and AS3 want to communicate and both have a lot of traffic, they can use separate policies so that they can send traffic directly to each other for free. This process lowers their bill, and this policy is known as peering.
  • In our example, PC-1, PC-2, and PC-3 are subnetworks because this is a single home computer or company network with multiple LANs. In PC-1, PC-2, and PC-3, the only space for sending assigned packets outside the network is on the AS2, AS3, and AS4 links, respectively.
  • Some company or organization networks are connected to multiple ISPs, improving reliability, if one path fails, the company uses a path through another ISP. This mechanism is known as multihoming.

Propagation of BGP Route Advertisements

BGP keeps track of the path used along with the cost of the route to each destination. This is known as path-vector routing. Pairs of BGP routers communicate and exchange path information by establishing a TCP connection. Using this approach, the reliability of the communication is increased, and the details of the network being passed through are hidden.

The example below illustrates how BGP route is advertised.

how BGP route is advertised
  • As shown in the figure, there are three autonomous systems present on the network. Central AS provides the transit policy to the ISP left and right.
  • Route advertisement for PC-1 has been started, and it is forwarded to Router-2C. Router-2c has the path to router-3a’s next-hop router. Router-2c has the same AS when it sends an advertisement to router-3b but has a different next-hop router. This advertisement is continuously propagated until it reaches AS1.
  • When the advertising packet reaches Router-1A, the path of the Advertisement packet is AS2, AS3, and the next hop is Router-2A.
  • The router checks the route to see if its own AS number is already in the AS path. If it gets its own AS number, it discards the advertisement.

How BGP Choose Route?

When the BGP router has found all the available routes to reach the destination, it decides the best route to be used to send the packet. The choice of the best route is based on the policy written by the ISP.


Below are strategies for finding the best route.

  • Routes through peer networks have higher priority than routes through transmit providers because it is free. Customer routes have the highest priority in which the ISP sends traffic directly to paying customersIn the second strategy, the BGP router finds the shorter AS path, which is the default rule. Here, the size of the AS can be large, so instead of sending the packet through one large AS, the BGP router sends the packet through two or three smaller AS.
  • In the last strategy, the BGP router finds the path that has the lowest cost within the ISP. We have used this strategy in Figure 4. This is also known as early exit or hot-potato rooting.
  • Finally, we can say that the BGP router finds the best route from the known probabilities. It may happen that the BGP router of one AS chooses different routes to reach the same destination in the other AS.

Key Points to Remember

Here is the list of key points we need to remember about “OSPF and BGP”.

  • BGP is an interdomain routing protocol, designed to allow a variety of routing policies to be implemented between autonomous systems.
  • BGP keeps track of the path used along with the cost of the route to each destination. This is known as path-vector routing.
  • BGP routers select routes based on various criteria, including AS path length, origin type (e.g., customer, peer, provider), and route cost. These criteria are specified in routing policies to optimize network performance and efficiency.
  • Many organizations connect to multiple ISPs to improve reliability. If one path fails, traffic can automatically reroute through another ISP, ensuring continuous connectivity. This is known as multihoming and is supported by BGP.


If you find any mistake above, kindly email to [email protected]

Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.