What is BGP route selection?
BGP route selection is the best-path algorithm that picks one route to a prefix from many candidates using a fixed, ordered list of tie-breaker attributes.
Last updated:
BGP route selection, also called the best-path algorithm, is the procedure by which a router chooses exactly one best route to a prefix out of many candidates and installs it in the routing table. BGP is a path-vector protocol and does not use a single metric like interior protocols do, so the decision is made by comparing path attributes one at a time in a strictly defined order. The first criterion that distinguishes two routes ends the comparison, and the remaining ones are never consulted.
Why BGP needs a best-path algorithm
A router often learns many parallel routes to the same prefix: from different transit providers, peering partners or its own iBGP neighbours. By definition BGP selects only one best path per prefix and re-advertises only that one. The algorithm must therefore be deterministic and identical on every router to avoid loops and inconsistency. Implementations following RFC 4271 use the same logical order, although Cisco adds its non-standard weight attribute, local to a single router, ahead of it.
The order of tie-breaker attributes
The algorithm walks through the criteria from highest priority to lowest. It first discards routes whose next hop is unreachable, then compares attributes in sequence until one of them breaks the tie.
- Weight (Cisco only, local to the router): highest wins. Then LOCAL_PREF: highest wins and steers egress for the whole AS.
- Locally originated routes (network, redistribute, aggregate) are preferred over routes learned from neighbours.
- Shortest AS_PATH, then lowest ORIGIN code (IGP < EGP < incomplete).
- Lowest MED, compared by default only between routes from the same neighbouring AS.
- Prefer eBGP over iBGP, then lowest IGP metric to the next hop, and finally the lowest Router ID as the ultimate tie-breaker.
Steering route selection in practice
Traffic engineering means deliberately influencing these criteria. LOCAL_PREF is the strongest practical lever for outbound traffic: setting it higher for peering than for transit pushes traffic down the cheaper path. Inbound traffic is harder to control because the remote network decides, so operators use AS_PATH prepending (artificially lengthening the path), MED between the same neighbour, and BGP communities that signal a desired policy to the upstream. Keep in mind that LOCAL_PREF and weight sit ahead of AS_PATH length in the algorithm, so overzealous prepending cannot override a policy your neighbour has already set.
Route selection in the AS202520 SkyPass network
In AS202520 SkyPass the best-path algorithm runs every day. In our Warsaw and Wrocław PoPs we learn the same prefixes via peering at THINX, TPIX, WRIX, POZIX and 1-IX and via IP transit, and best-path automatically prefers the shorter, cheaper peering paths. We expose BGP communities to peering and IP transit customers for steering LOCAL_PREF and prepending, and our public looking glass lets you see which route to a given prefix our router actually selected and why.
Frequently asked questions
What is the first BGP route selection criterion?
On Cisco routers the non-standard weight attribute is compared first (highest wins, local to the router). In a pure RFC 4271 implementation the first criterion is the highest LOCAL_PREF.
Does the shortest AS path always win?
No. AS_PATH is compared only after weight and LOCAL_PREF, so a higher LOCAL_PREF beats a shorter AS path. That is why prepending fails if the remote network has already set a higher LOCAL_PREF for another route.
When is MED compared?
By default MED is compared only between routes originating from the same neighbouring AS. The always-compare-med option lets you compare MED across different AS, but it is used with care.
What breaks the tie when all attributes are equal?
The router prefers eBGP over iBGP, then the lowest IGP metric to the next hop, and if that still ties, it picks the route from the neighbour with the lowest Router ID.
