Table of Contents
Introduction
Border Gateway Protocol, or BGP, is the routing protocol that holds the global internet together. While other routing protocols such as RIP, OSPF, or EIGRP focus on routing inside a single organization, BGP is primarily about exchanging routing information between different organizations, usually called autonomous systems. It is often described as a path vector protocol and is highly policy driven. For beginners, the most important ideas are what BGP does, how it sees the world, and how it chooses routes.
Autonomous Systems and BGP’s Role
BGP works at the level of autonomous systems, often abbreviated as AS. An AS is a collection of IP networks and routers under a single administrative control, such as an ISP, a large enterprise, or a cloud provider, which presents a common routing policy to the internet.
Each AS has a unique number, called an Autonomous System Number, or ASN. When BGP routers exchange routes, they attach the sequence of ASNs that traffic must pass through to reach a destination. This sequence is the AS path. So instead of just learning “here is a route to 203.0.113.0/24,” a BGP router learns something like “to reach 203.0.113.0/24, follow AS 65010, then AS 64512, then AS 65020.”
BGP is the main protocol used between autonomous systems. This is called external BGP, or eBGP. The same protocol can also run within a single AS, which is called internal BGP, or iBGP. The distinction between internal and external BGP is about where the peers live relative to AS boundaries, not about different protocol versions.
Path Vector Basics
BGP is called a path vector protocol because it adds a path, expressed as an ordered list of ASNs, to each advertised network. When a route is advertised, each AS that forwards it appends its own ASN to the AS_PATH attribute. This turns a simple “distance” into a “which path through which ASes” view.
One important result is loop avoidance. If a BGP router receives an advertisement for a route and sees its own ASN already in the AS path, it knows this route has looped around and can safely discard it. The protocol does not need to flood raw link-state information like OSPF, or rely only on neighbor counts like simple distance vector protocols. Instead, it works with whole paths through ASes.
eBGP vs iBGP
There are two main ways BGP sessions are used.
In eBGP, two routers in different autonomous systems form a BGP session and exchange routes. The purpose here is interdomain routing, meaning routing between separate administrative domains. In practice this is what ISPs use to exchange reachability to their customers and to the rest of the internet. eBGP sessions typically sit on directly connected links between providers and customers or between peer ISPs.
In iBGP, routers inside the same autonomous system form sessions to share BGP-learned routes among themselves. iBGP does not change the AS path when routes are exchanged internally, because all routers are part of the same AS. The goal is to distribute knowledge learned from eBGP peers throughout the AS so that any border router can forward traffic correctly.
This difference leads to an important rule, which many learners first meet in BGP: a route learned via iBGP is not re-advertised to another iBGP peer by default. This is handled by BGP design to avoid loops inside an AS and leads to the need for specific iBGP topologies and techniques, which are covered when studying internal BGP in more detail.
Important: eBGP sessions are between different ASNs. iBGP sessions are between routers with the same ASN. BGP prevents iBGP-learned routes from being re-advertised to other iBGP peers by default.
BGP Messages and Sessions
BGP uses TCP as its transport, usually on port 179. This means BGP benefits from TCP reliability and does not have to handle packet loss itself. A BGP session is a long-lived TCP connection between two BGP speaking routers, called BGP peers or BGP neighbors.
The main BGP message types are:
| Message type | Purpose |
|---|---|
| OPEN | Establish a BGP session and exchange basic parameters, such as ASN and timers. |
| KEEPALIVE | Confirm that the BGP session is still alive, without sending routing updates. |
| UPDATE | Advertise new routes or withdraw routes that are no longer valid. |
| NOTIFICATION | Signal an error and usually close the session. |
Once the OPEN messages are successfully exchanged and the session is established, most of the work happens through UPDATE and KEEPALIVE messages. KEEPALIVE messages maintain the relationship, and UPDATE messages carry network layer reachability information, sometimes shortened to NLRI, along with BGP attributes.
Because BGP runs over TCP, packet ordering and retransmissions are handled below BGP. This is one of the reasons BGP is considered stable and reliable for large-scale routing.
BGP Attributes and Route Selection
Every BGP route is more than a prefix and a next hop. It carries attributes that describe properties of the route and that can be used to apply routing policies. You will meet many of these attributes in more advanced study, but some high level ideas are useful now.
Attributes fall into categories such as well-known mandatory, well-known discretionary, and optional. For beginners, it is more important to know that attributes exist and that routers use them to decide which route to prefer when multiple BGP routes to the same prefix are available.
Some key attributes you will hear about include:
| Attribute | High level idea |
|---|---|
| AS_PATH | The sequence of ASNs that the route has passed through. Used for loop prevention and path selection. |
| NEXT_HOP | The IP address of the next router used to reach the advertised prefix. |
| LOCAL_PREF | A value used inside an AS to prefer one exit point over another. Higher is usually more preferred. |
| MED | Multi Exit Discriminator, a value used to suggest which entry point into an AS is preferred. Lower is usually more preferred. |
When a BGP router has more than one path to a destination, it follows a route selection process that considers these attributes in a defined order. The exact list can depend on implementation, but typically it starts with discarding unusable routes, then prefers the highest LOCAL_PREF, then the shortest AS_PATH, and continues through several criteria. The important idea in this chapter is that BGP is policy based. Administrators adjust attributes to influence traffic flows without simply relying on the shortest path in terms of hop count.
Key idea: BGP does not simply pick “shortest distance.” It chooses routes based on a sequence of attribute comparisons, such as LOCAL_PREF and AS_PATH, to implement routing policy.
BGP as a Policy-Based Protocol
Unlike many internal routing protocols, BGP is primarily about expressing and enforcing policy between autonomous systems. Policy in this context means which prefixes to advertise to which neighbors, which routes to accept, and which routes to prefer for outbound traffic.
Common policy goals include controlling which prefixes are reachable from the internet, influencing which upstream provider is used as the primary exit, balancing traffic over multiple providers, and protecting against accidental or malicious route advertisements.
To implement these policies, network operators use tools such as prefix filters to limit what routes can be accepted or advertised, and manipulation of attributes such as LOCAL_PREF, AS_PATH prepending, or MED to “steer” route selection. The details of these techniques belong to more advanced chapters, but the conceptual difference is essential: BGP is the protocol where human business and operational decisions meet the technical routing system.
Internet Scale and Convergence Characteristics
BGP operates at internet scale. A full table of internet IPv4 routes can include hundreds of thousands of prefixes, and similar growth exists in IPv6. BGP routers must be capable of storing and processing very large routing tables and handling frequent incremental updates.
Because of its scale and policy nature, BGP typically converges more slowly than many interior routing protocols. Convergence here means the time needed for all BGP routers involved to agree on new routes after a topology or policy change. The protocol is designed to prioritize stability over speed, to avoid constant route flapping across the global internet.
Mechanisms such as route dampening can be used to reduce the impact of unstable routes, but at the cost of longer convergence for those routes. For a beginner, the takeaway is that BGP is not optimized for fast reaction at small scales, but for stable, controlled routing among large, independent networks.
Use Cases and Where You Meet BGP
In practice, BGP appears in several key situations.
At the edge of an ISP network BGP is used to connect to other ISPs and to customer autonomous systems. This is the most visible part, as it is where global internet reachability information is exchanged.
Enterprises that connect to more than one ISP, a situation often called multihoming, commonly use BGP to exchange routes with each provider. This lets them influence inbound and outbound traffic paths and provides resilience if one provider fails.
Inside very large networks, such as major service providers or large cloud environments, BGP can also be used internally as a scalable routing mechanism, both in traditional designs and in advanced data center fabrics. In these uses BGP is still the same protocol, but it is applied within the organization over iBGP sessions and sometimes in conjunction with other mechanisms.
Security Considerations at a High Level
Because BGP controls how traffic is routed between organizations, incorrect or malicious BGP advertisements can have serious effects, such as redirecting or blackholing traffic. At a high level, operators use techniques such as careful prefix filtering, authentication of BGP sessions, and participation in route validation systems to reduce these risks.
The key conceptual point is that BGP trusts what its neighbors tell it, subject to the policies and filters that administrators configure. Strong and thoughtful policies around what is accepted and what is advertised are therefore a central part of safe BGP operation.
Important: BGP trusts received route information unless filtered or validated. Incorrect policies or missing filters can lead to large-scale traffic misrouting.
Summary
BGP is the protocol that enables routing between autonomous systems on the internet. It is a path vector protocol that attaches AS paths and other attributes to each route, and it uses a structured decision process to select preferred routes based on policy, not just distance. It runs over TCP, forms long-lived sessions between BGP peers, and exchanges routes with associated attributes to control traffic flows. In the context of routing protocols, BGP is the tool for interdomain routing and policy expression, especially at internet scale and at the edges of networks that need to interact with external providers.