BGP Path Selection
Watch routes propagate AS-by-AS, see the decision process pick best paths, and shift traffic with prepending.
How BGP Path Selection Works
BGP (Border Gateway Protocol) is the routing protocol that glues together the roughly 100,000 autonomous systems (ASes) that make up the internet. Each AS — an ISP, cloud provider, university, or enterprise — runs BGP to exchange reachability information with its neighbors.
AS paths build hop-by-hop
When AS 100 originates a route to 10.0.0.0/8, it tells its neighbors "I can reach this prefix." Each neighbor prepends its own AS number to the path before passing the announcement onward. So AS 200 advertises the path [200, 100], AS 400 learns [400, 200, 100] from AS 200, and so on. If an AS sees its own number already in the path, it drops the announcement — that's loop detection.
The decision process
When an AS learns multiple routes to the same prefix from different neighbors, it needs to pick one. The simplified decision process used here mirrors the real one:
- Highest local preference — an operator-configured weight, usually used to prefer one upstream over another
- Shortest AS path — fewer hops generally means a more direct route
- Lowest neighbor AS number — a tiebreaker when all else is equal
In practice, the real BGP decision process has more steps (origin type, MED, IGP cost, router ID), but AS path length is the most common differentiator.
AS path prepending
Since BGP prefers shorter paths, an AS can make one of its paths look less attractive by prepending its own AS number extra times. If AS 100 normally advertises [100] but prepends once, its neighbors see [100, 100] — which looks two hops long. Traffic shifts to alternate shorter paths without changing any physical connectivity. This is one of the simplest forms of BGP traffic engineering.