What is BGP?
The internet is tens of thousands of separate networks, called autonomous systems, each with its own number. BGP is how they tell each other which addresses they can reach. Every router at the edge of a network learns paths from its neighbours and picks the best one by policy, not just distance.
BGP runs quietly until it goes wrong. A typo in one announcement can send a country's traffic the wrong way, and a big network withdrawing its routes can make its services vanish. Understanding BGP explains many of the largest internet outages.
Think of it like this. BGP is like neighbouring countries sharing road maps at their borders. Each country says which towns it can get you to and through which countries. You pick a route based on your own rules, like the fewest borders or a friendly neighbour. If a country lies about a town it does not have, drivers get sent the wrong way.
Step by step
Normal
5 stepsTwo networks start a BGP session, then one announces its addresses and the news spreads, gaining an AS on every hop.
Normal
5 stepsTwo networks start a BGP session, then one announces its addresses and the news spreads, gaining an AS on every hop.
- 1
TCP to port 179
A plain TCP connection
Two routers in different networks (autonomous systems) are configured as neighbours by hand. One opens a TCP connection to the other on port 179.
- 2
OPEN
Who are you, what can you do?
Each side sends an OPEN with its AS number, a hold time and the features it supports. If the AS number is not the one configured, the session is refused.
- 3
KEEPALIVE
Session established
A KEEPALIVE confirms the OPEN. From now on each side sends one every third of the hold time, here every 30 seconds, so the other knows it is alive.
- 4
UPDATE
I can reach 203.0.113.0/24
The content network announces its address block. The UPDATE carries attributes, mainly AS_PATH and NEXT_HOP, that others use to pick the best route.
- 5
Spreading
AS_PATH grows by one
The transit network adds its own AS to the front of the path and tells its other neighbours, including your ISP. Within seconds to minutes, networks across the world know the way.
Link fails
4 stepsKeepalives stop, the hold timer runs out, and a withdrawal tells everyone to use the backup path.
Link fails
4 stepsKeepalives stop, the hold timer runs out, and a withdrawal tells everyone to use the backup path.
- 1
Silence
Keepalives are lost
A fibre between the transit and the content network is damaged in a way the routers do not notice at once. Keepalives stop getting through.
- 2
Hold timer expires
90 seconds without a word
When the hold time passes with nothing heard, the transit router sends a NOTIFICATION, closes the session and drops every route it learned from that neighbour.
- 3
Withdraw
Forget 203.0.113.0/24 via me
The transit router sends an UPDATE with the prefix in its withdrawn routes list to its other neighbours. Your ISP removes that path.
- 4
Backup path
Via AS 64503
Your ISP still has the route through the backup transit, so traffic moves there. Users may see a short pause, not an outage. Many networks add BFD, a fast hello check, to notice in under a second instead of 90.
Route hijack
4 stepsA network wrongly announces someone else's addresses, more specifically, and traffic follows it.
Route hijack
4 stepsA network wrongly announces someone else's addresses, more specifically, and traffic follows it.
- 1
Wrong announcement
203.0.113.0/25 and /25
AS 64511 announces two halves of 203.0.113.0/24, which is not its block. This is usually a typo or a leaked internal route, sometimes an attack.
- 2
Passed along
No filter checks it
Its upstream, the backup transit, does not check what this customer may announce. It adds its own AS and passes both routes on to your ISP.
- 3
Longest match wins
/25 beats /24
Routers always prefer the most specific prefix, whatever the AS path. Your ISP now sends all traffic for 203.0.113.0/24 toward AS 64511.
- 4
Traffic lost
Users cannot reach the site
Requests end in the wrong network and are dropped or answered by the wrong machine. A famous 2008 mistake like this took a large video site offline worldwide for about two hours.
Hijack blocked
3 stepsWith RPKI route origin validation, the same bad announcement is rejected at the first network that checks.
Hijack blocked
3 stepsWith RPKI route origin validation, the same bad announcement is rejected at the first network that checks.
- 1
Signed ownership
A ROA for 203.0.113.0/24
The owner of 203.0.113.0/24 has published a signed Route Origin Authorization: only AS 64502 may announce it, and nothing longer than /24.
- 2
Router loads the list
From a validator
The backup transit's router fetches the checked list of authorizations from its own RPKI validator over the RPKI-to-Router protocol.
- 3
Invalid, dropped
Wrong origin, too specific
The bad /25 routes come from AS 64511 and are longer than allowed, so they are marked Invalid and rejected. Your ISP never hears them, and traffic keeps flowing to the real owner.
Myths and mix-ups
- BGP does not pick the fastest path; it picks by policy and AS path length, with no idea of speed or delay.
- BGP is not only for giant companies; any network with its own addresses and two providers can run it.
- BGP itself does not check who owns an address block; RPKI and filters add that check.
- A BGP outage is not a hacked website; the servers may be fine while the routes to them are gone.
Try it yourself
Run these on your own computer to see BGP at work.
See network numbers on your path (macOS)
traceroute -a example.com-a looks up the AS number of each hop, so you can see where one network hands over to the next.
See network numbers on your path (Linux)
traceroute -A example.com-A adds the AS path lookup for each hop. Install the traceroute package if it is missing.
Live path with AS numbers (macOS or Linux)
mtr -z example.commtr keeps probing and shows the AS for each hop. Press q to quit.
Trace the path (Windows)
tracert example.comNo AS numbers here, but the jump in hop names often shows where networks meet.
BGP at a glance
- Layer
- Application (7), runs over TCP
- Port
- TCP 179
- Message types
- OPEN, UPDATE, KEEPALIVE, NOTIFICATION, ROUTE-REFRESH
- Common hold time
- 90 or 180 seconds, keepalive one third of it
- Route choice
- Policy first, then shortest AS path and more
- Private AS numbers
- 64512 to 65534 (RFC 6996)
- Defined in
- RFC 4271 (BGP-4, 2006)
Defined inRFC 4271RFC 4760RFC 6793RFC 6811RFC 8210
Header fields
What BGP puts in its messages, with example values from the stories above.
BGP
- Marker
ffffffffffffffffffffffffffffffff- Length
49 bytes- Type
1 (OPEN)- Version
4- My AS
64502Which network this router speaks for. 64496 to 64511 are numbers set aside for examples.- Hold time
90 secondsIf nothing is heard for this long, the session is declared dead. Both sides use the lower value.- BGP identifier
203.0.113.1- Capabilities
IPv4 unicast, route refresh, 4-octet AS numbers- Withdrawn routes
203.0.113.0/24I can no longer reach these addresses. Remove my path.- ORIGIN
IGPThe route was created inside the network that owns it.
Test yourself
Which port and transport does BGP use?
Questions people ask
What is BGP in simple terms?
The protocol networks use to tell each other which IP addresses they can reach. It is how the internet's separate networks build a shared map of routes.
What is an autonomous system number?
A number that identifies one network with its own routing policy, like an internet provider or a large company. BGP uses it to describe paths. Numbers 64512 to 65534 are private, like private IP addresses.
What is a BGP hijack?
When a network announces IP addresses it does not own, by mistake or on purpose, and other networks believe it. Traffic for those addresses then goes to the wrong place.
What is the difference between BGP and OSPF?
OSPF finds the shortest paths inside one network. BGP exchanges routes between different networks and picks paths by policy. Most large networks run both.
Why is BGP blamed for big outages?
One wrong announcement or withdrawal spreads to the whole internet within minutes. If a network withdraws its own routes, nobody can find its servers even though they are running.