Best-path selection
A router often learns the same prefix from several peers. BGP installs exactly one best path per prefix (unless multipath is enabled) by walking down an ordered list of tie-breakers and stopping at the first one that produces a single winner.
The common order (Cisco IOS and FRR are nearly identical):
- Highest weight — local to the router, never advertised. (Cisco/FRR only.)
- Highest LOCAL_PREF — AS-wide outbound preference.
- Locally originated — prefer routes this router injected itself.
- Shortest AS_PATH
- Lowest ORIGIN — IGP < EGP < incomplete.
- Lowest MED — by default only compared between routes from the same neighbouring AS.
- eBGP over iBGP
- Lowest IGP metric to the NEXT_HOP — "hot-potato" routing: leave the network at the nearest exit.
- Oldest eBGP path — stability (not modelled in the simulator).
- Lowest router ID
- Lowest neighbour address
Before any of this, a path must be valid: its NEXT_HOP must be reachable and it must not contain a loop.
The key insight for design: steps 1–2 are your policy, steps 4–8 are the network's opinion. Operators rarely rely on AS_PATH length alone — they set LOCAL_PREF from inbound route-maps to express "prefer the customer, then the peer, then transit".
Try these in the simulator. By default all three paths have equal AS_PATH length, so R3 loses at eBGP over iBGP and ISP A beats ISP B on router ID.
- Give R3 (iBGP) a LOCAL_PREF of 200. It now wins despite being iBGP — policy beats everything below it.
- Reset, then prepend on ISP A by changing its AS_PATH to
64497 64497 64497 64499. ISP B wins on path length. - Reset, then give ISP A a MED of 50 and ISP B a MED of 10. Nothing changes: MED is only compared between paths from the same neighbouring AS, and these come from 64497 and 64498. Tick always-compare-med and ISP B wins.
Interactive: Best-path simulator Three routers in AS 64500 have learnt 203.0.113.0/24. Edit any attribute and watch the decision change. (needs JavaScript)
Check your understanding
Two eBGP routes have identical weight, LOCAL_PREF and AS_PATH length. One has ORIGIN incomplete (?) and MED 0; the other has ORIGIN IGP (i) and MED 500. Which wins?
- The MED 0 route, because lower MED is preferred
- The ORIGIN IGP route
- Whichever was received first