Skip to content
Fresh IPv4 news just dropped — 🎉 see what you’re missing

What Is BGP? How the Border Gateway Protocol Works

BGP (Border Gateway Protocol) exchanges IP reachability information between routers and selects routes according to policy. It connects autonomous systems across the internet and distributes external routes within a network. Its decisions depend on route attributes and operator policy, rather than measured latency or link bandwidth.

What routers exchange

A BGP announcement pairs a destination prefix with attributes describing how it can be reached. It does not assign addresses, create a physical connection, or prove permission to originate a prefix. RFC 4271 defines the base BGP-4 protocol.

The ASN guide explains the autonomous system identifiers used in announcements. BGP uses those identifiers; it does not issue them.

IPv4 unicast is one address family. Multiprotocol BGP, defined in RFC 4760, adds support for other families, including IPv6. Peers negotiate supported families, so a working IPv4 session does not by itself establish that IPv6 routes are being exchanged.

eBGP and iBGP have different jobs

Session typeWhere it runsRole
External BGP, or eBGPBetween different autonomous systemsExchange routes with transit providers, peers, or customers
Internal BGP, or iBGPBetween routers in the same autonomous systemDistribute BGP routes across the operator’s network

iBGP does not replace the underlying connectivity needed to reach a BGP next hop. An interior routing protocol or static routes commonly provide that reachability.

In ordinary iBGP, a route learned from one iBGP neighbor is not advertised to another iBGP neighbor. A full mesh addresses that constraint in small networks. Larger networks commonly use route reflectors, described in RFC 4456, to distribute routes without every router peering directly with every other router. Route reflection also affects which paths each router can see.

Two external transit ASes connect through eBGP to edge routers R1 and R2 in AS64496. Inside that AS, R1 and R2 use iBGP sessions to a route reflector. Solid blue and dashed green lines identify session types, not physical cables or packet paths.
eBGP crosses an AS boundary. iBGP distributes routes within the same AS; this example uses a route reflector.

Open the eBGP/iBGP diagram as SVG.

How a BGP session comes up

BGP uses TCP, normally with destination port 179. The peers establish the transport connection, exchange OPEN messages, and reach the Established state before exchanging routes.

Core messagePurpose
OPENExchange session parameters and capabilities
KEEPALIVEMaintain the session without carrying route updates
UPDATEAdvertise routes, change attributes, or withdraw routes
NOTIFICATIONReport a protocol error and close the session

The session state machine includes Idle, Connect, Active, OpenSent, OpenConfirm, and Established. Active means the router is trying to establish transport connectivity; it does not mean the peering is working.

Route exchange is incremental after the initial exchange. A withdrawal removes a previously advertised path; a replacement path may then become usable. Detection timers, processing, and policy affect convergence, so BGP failover is not instantaneous.

From an UPDATE to packet forwarding

A route can be received without being accepted, selected, installed, or exported. Treat these as separate checkpoints:

An exploded stack separates received routes, import policy, and BGP best-path selection. Selection branches to local routing-table and FIB installation, and separately to export policy for each neighbor. Received does not mean accepted, accepted does not mean selected, and selected does not mean installed.
Route processing has separate local-forwarding and neighbor-export outcomes. An established BGP session does not guarantee reachability.

Open the route-processing diagram as SVG.

The BGP table can hold several paths for one prefix. A BGP best path still competes with other route sources for installation in the routing table. Export policy separately determines what each neighbor receives.

Best-path comparison is for the same prefix. Packet forwarding uses the longest matching installed prefix. A /24 and a covering /23 are separate destinations in the routing table; a higher preference on the /23 does not override longest-prefix matching. The CIDR chart shows those prefix boundaries.

Attributes that influence routing policy

These are common inputs, not a universal ordered algorithm. Vendors expose additional controls and tie-breakers; Cisco’s best-path documentation describes one implementation.

AttributeOperational useLimit to remember
LOCAL_PREFPrefer an exit within your AS; higher values are preferredNormally distributed through iBGP, not sent to ordinary eBGP neighbors
AS_PATHRecord AS-level propagation and detect loopsShorter paths are not necessarily faster or preferred by policy
NEXT_HOPIdentify the next-hop address for the routeIt must be reachable for the path to be usable
MEDSuggest a preferred entry when adjacent networks have multiple connectionsLower is normally preferred; comparison scope depends on implementation and configuration
CommunitiesAttach labels that routing policy can matchA label has an effect only where a policy interprets it

RFC 1997 defines the original communities attribute. Providers publish community meanings for actions such as regional export control or prepending. Confirm the provider’s documented semantics and whether communities are preserved before relying on them.

Example: policy can prefer a longer AS path

An operator receives two eligible paths to the same prefix:

PathDestinationAS_PATHLOCAL_PREF
A192.0.2.0/2464497 64496100
B192.0.2.0/2464498 64499 64496200

Assume both next hops are reachable, higher-priority selection inputs are equal, and the implementation considers LOCAL_PREF before AS-path length. Path B wins because its local preference is higher, despite its longer AS path.

These are illustrative documentation addresses and ASNs. Setting LOCAL_PREF chooses your network’s outbound preference; it does not instruct remote networks to send inbound traffic through the same provider. The example demonstrates policy selection, not a latency prediction.

Import and export policies define the boundary

Write an explicit policy for every external session. Import policy decides which routes to accept and how to classify them. Export policy decides which routes a neighbor is allowed to learn.

RFC 8212 specifies default rejection for eBGP route exchange without the corresponding policies. Confirm implementation behavior: an established session may exchange no usable routes until policy is configured.

RFC 7454 describes operational protections, including prefix, AS-path, and next-hop filtering and maximum-prefix limits. Permit only the intended prefixes and lengths on export. A network connected to two transit providers should not accidentally advertise one provider’s routes to the other and become unintended transit. Monitor prefix counts and understand whether a configured limit warns, rejects routes, or shuts down the session.

Origin validation adds another check. RPKI route origin validation compares the announced prefix, length, and origin ASN with covering authorizations. A valid origin does not validate the full AS path or prove that the route was exported appropriately; origin-valid routes can still be leaked.

Check the route, not just the session

In FRRouting, these read-only commands separate session status from route selection and export:

show bgp ipv4 unicast summary
show bgp ipv4 unicast 192.0.2.0/24
show bgp ipv4 unicast neighbors 198.51.100.1 advertised-routes
show ip route 192.0.2.0/24

Run them in FRR’s vtysh shell, substituting your actual prefix and neighbor. The addresses above are examples, not live targets.

SymptomCheck next
Session stays Idle or ActiveNeighbor addressing, TCP reachability, remote ASN, and session authentication
Established, but no accepted prefixesNegotiated address family, import policy, and whether the peer exports the expected routes
Prefix is in BGP but not usedNext-hop reachability, the selected BGP path, and routing-table competition
Route is selected locally but absent remotelyPer-neighbor export policy, upstream filters, and the observed origin
Route is visible but the service failsForwarding state, return route, ACLs, MTU, and service health

Use WHOIS and RDAP to check registry records separately from the live announcement. A looking glass shows one network’s view; verify from relevant external networks and test actual traffic in both directions.

For a newly moved block, the post-transfer checklist connects these routing checks with registry and authorization changes. Obtaining space through IPv4 services and making it reachable are separate operational steps.

Frequently asked questions

What is BGP used for?
BGP exchanges network reachability information and applies routing policy. It connects autonomous systems through eBGP and distributes BGP routes inside an AS through iBGP.
What is the difference between BGP and an ASN?
BGP is the routing protocol. An ASN is the numeric identifier for an autonomous system that participates in BGP. The ASN page explains number formats and public and private ranges.
Does BGP always choose the shortest path?
No. Import policy, path eligibility, and attributes such as LOCAL_PREF affect selection before AS-path length is considered. BGP does not measure end-to-end latency or bandwidth when choosing a route.
Why is my BGP session established but no traffic passes?
An established session confirms that the peers can exchange BGP messages. Routes may still be filtered, lack a reachable next hop, lose routing-table selection, or fail forwarding. Check received routes, accepted paths, the routing and forwarding tables, exported routes, and the return path.
Do I need a full internet routing table to use BGP?
No. A BGP session can exchange a default route, a selected set of prefixes, or a full table. The choice depends on the routing decisions you need to make and the router’s control-plane and forwarding capacity.
Last updated on