For many engineers new to BGP (Border Gateway Protocol), a common question arises:
“When multiple BGP routes to the same destination exist, how does the router decide which one to use?”
The answer lies in BGP’s best path selection rules. BGP follows a strict order of comparison, attribute by attribute, until it finds the optimal route. Mastering this process is essential both for learning BGP fundamentals and for troubleshooting complex network issues.
Unlike OSPF or IS-IS, which are designed for internal routing, BGP controls routing across the Internet. A single prefix can be advertised by multiple neighbors, so BGP must use a consistent logic to avoid routing instability and conflicts.
Across most vendors (Cisco, Huawei, Juniper), BGP follows this general order of preference:
Weight – Cisco-specific attribute; higher value is preferred. Used for local router decisions.
Local Preference – Vendor-independent; higher value wins. Often used to influence outbound traffic.
Locally Originated Routes – Routes originated by the router itself (via network
or aggregate
) are preferred over learned routes.
AS Path Length – Shorter AS Path is preferred, representing fewer autonomous systems.
Origin Type – Preference order: IGP > EGP > Incomplete.
MED (Multi-Exit Discriminator) – Lower MED is preferred. Used for inbound traffic control between ISPs.
eBGP vs iBGP – Routes learned from eBGP are preferred over those from iBGP.
IGP Metric to Next Hop – The route with the closest next hop is chosen.
Router ID – As the final tiebreaker, the route with the lowest Router-ID wins.
Imagine two routes to reach 10.1.1.0/24
:
From ISP A: AS Path = 65001 65002
From ISP B: AS Path = 65003
If no Weight or Local Preference is set, the router compares AS Path length:
ISP A path length = 2
ISP B path length = 1
The router selects ISP B’s route.
However, if you configure a higher Local Preference for ISP A, the router will prefer ISP A’s route, regardless of AS Path length.
Traffic Engineering – Control which ISP your outbound traffic uses.
Troubleshooting – When an “expected route” is not chosen, analyze each attribute step by step.
Network Security – Knowledge of BGP logic helps mitigate route hijacking and misconfigurations.
BGP path selection is not random—it follows a strict priority chain:
Weight → Local Preference → Locally Originated → AS Path → Origin → MED → eBGP Preference → IGP Metric → Router ID
By remembering this order, you can quickly determine why a router selects one path over another and make precise routing adjustments in real-world networks.