BGP Best Path Selection: Every Tie-Breaker in Order
Fifteen routers hand the RouteViews route server a path to 8.8.8.0/24, ten of them equally short, and the router picks path number 12, via AS 101. Not the path from the lowest router ID, not the first one in the list, and nothing in the output says why. BGP best path selection is the ordered list of tie-breakers that a BGP speaker walks through until only one path is left: weight, LOCAL_PREF, locally originated, AS_PATH length, ORIGIN, MED, eBGP over iBGP, IGP cost, the age of the path, router ID and finally the neighbor address. Every network engineer has seen that list. What it hides is where the vendors differ, which steps the RFC actually defines, and the late tie-breakers that decide most real Internet routes. In this part we take the algorithm apart step by step, compare RFC 4271 with Cisco IOS, IOS XR, Junos, FRR and GoBGP, prove each step in a GoBGP lab with hand-built UPDATEs, read real IOS XR outputs, and replay the decision on 63 real paths from a public route server.
- The order (Cisco IOS): weight, LOCAL_PREF, locally originated, AS_PATH, ORIGIN, MED, eBGP over iBGP, IGP metric, multipath check, oldest eBGP path, router ID, CLUSTER_LIST length, neighbor address.[8]
- The RFC is smaller: RFC 4271 has LOCAL_PREF as a Phase 1 preference and seven tie-breakers a-g. Weight, local origin and the oldest-path rule are vendor or later-RFC additions.[1][3]
- Vendors differ at the edges: Junos has no weight, FRR's documentation and code disagree on the last step, GoBGP 4.11 has no IGP-cost or CLUSTER_LIST step and ignores ORIGINATOR_ID.[9][10][11][13]
- Real decisions happen late: on RouteViews 3 of 4 prefixes were decided after the IGP step, by the age of the path. FRR in Sydney says so in plain text:
best (Older Path).[15][16] - Lab proof: in GoBGP an older eBGP path beat a lower router ID, and one community change re-aged a path and flipped the best path.[17]
- MED breaks transitivity: without deterministic grouping, three paths can produce three different winners depending on arrival order.[7][8][9]
BGP best path selection order at a glance
Before the details, the list most engineers learn, in the order Cisco documents it in its "Select BGP Best-path Algorithm" note.[8] A path is only a candidate if its NEXT_HOP is reachable, it passed inbound policy and its AS_PATH does not contain the local AS; other paths never enter the comparison.[1][8]
- Highest weight (Cisco-local, 32768 for locally originated paths, 0 for received ones).
- Highest LOCAL_PREF (missing =
bgp default local-preference, 100 by default). - Locally originated (
networkandredistributebeforeaggregate-address). - Shortest AS_PATH (an AS_SET counts as 1, confederation segments are not counted).
- Lowest ORIGIN (IGP < EGP < INCOMPLETE).
- Lowest MED, only between paths from the same neighbor AS; a missing MED is 0.
- eBGP over iBGP (confederation paths count as internal).
- Lowest IGP metric to the NEXT_HOP.
- Multipath check: paths still tied here may be installed together (
maximum-paths). - Oldest path, when both are eBGP paths.
- Lowest router ID (the ORIGINATOR_ID replaces it for reflected routes).
- Shortest CLUSTER_LIST.
- Lowest neighbor address.
A popular memory aid, "We Love Oranges AS Oranges Mean Pure Refreshment" (Weight, LOCAL_PREF, Originate, AS_PATH, ORIGIN, MED, Paths eBGP, Router ID), skips the IGP metric, the age and the last two steps, and those decide many real routes. Use it as a hint, not as the algorithm. Each step only matters if all earlier steps tied: a higher weight or LOCAL_PREF makes everything below it irrelevant, and a different AS_PATH length makes the MED invisible.
What RFC 4271 actually specifies
RFC 4271, the BGP-4 specification, describes a decision process in three phases and calls it "conceptual": an implementation may differ "as long as the implementations support the described functionality and they exhibit the same externally visible behavior".[1]
Phase 1 computes a degree of preference for every route in the Adj-RIBs-In. For a route from an internal peer it is the LOCAL_PREF value (or a locally computed value, which the RFC warns may form persistent loops). For a route from an external peer it is computed from local policy, and "the return value MUST be used as the LOCAL_PREF value in any IBGP readvertisement". This is why LOCAL_PREF sits above everything else: it is the preference itself.[1]
Phase 2 selects one route per destination. Before it starts, a route MUST be excluded if its NEXT_HOP "is not resolvable, or if it would become unresolvable if the route was installed", and a route whose AS_PATH contains the local AS "should be excluded". Among the remaining routes the one with the highest degree of preference wins. Only when several routes share that value does section 9.1.2.2 apply, and "the criteria MUST be applied in the order specified":[1]
- a) fewest AS numbers in AS_PATH, where "an AS_SET counts as 1, no matter how many ASes are in the set";
- b) lowest ORIGIN;
- c) lowest MULTI_EXIT_DISC, "only comparable between routes learned from the same neighboring AS", with a missing MED treated as the lowest value, 0;
- d) if at least one route came via eBGP, remove all iBGP routes;
- e) lowest interior cost to the NEXT_HOP;
- f) lowest BGP Identifier of the advertising speaker;
- g) lowest peer address.
Phase 3 then copies the Loc-RIB into the Adj-RIBs-Out through each peer's export policy. Three later RFCs add to Phase 2. RFC 4456 (route reflection) replaces the BGP Identifier with the ORIGINATOR_ID and inserts a CLUSTER_LIST length step; parts 14 and 15 of this series tested both.[2] RFC 7311 (AIGP) says its procedure "MUST be executed BEFORE any of the tie-breaking procedures" of 9.1.2.2.[6] And RFC 5004 notes that for external paths the BGP Identifier is "just a random number" from the local router's point of view, so when neither the current best external path A nor a new external path B has been eliminated before step f, "the existing best path (Path A) be kept".[3] That is the standard behind the oldest-path rule that many engineers skip when they learn the list.
RFC 4277, the operational experience document, is less enthusiastic about time-based rules: "temporal behavior in route selection results in non-deterministic behavior, and as such, may often be undesirable".[4] Both views are implemented today, and the knob that switches between them is one of the most useful in this article.
Cisco, Junos, FRR, GoBGP: six orderings side by side
The middle of the algorithm, from AS_PATH length to IGP metric, is the same everywhere. The differences sit at both ends:
- Weight. Cisco IOS, IOS XR and FRR check a router-local weight first.[8][9][11] Junos has no weight; its first comparison is the route preference (what Cisco calls administrative distance), and LOCAL_PREF comes next.[10] FRR adds an admin-distance check as step 0 when one route is redistributed locally and another is aggregated or received.[11]
- Locally originated. Cisco and FRR prefer local routes right after LOCAL_PREF. Junos prefers "strictly internal paths" much later, after MED.[10] IOS XR has its own first step: a path is invalid if it has an unreachable next hop or "the maximum possible MED value"; Cisco IOS documents special handling of MED 4,294,967,295 as well.[8][9]
- AIGP. Junos and FRR (
bgp bestpath aigp) evaluate AIGP after LOCAL_PREF, Cisco IOS documents it as a note to the local-origin step, and the IOS XR list we used does not mention it.[8][9][10][11] - Oldest path. Cisco prefers "the path that was received first (the oldest one)" when both are external, and skips the rule with
bgp bestpath compare-routerid, when the paths come from the same router, or when there is no current best path.[8] Junos uses the same rule with four exceptions, among thempath-selection external-router-idand "neither path is the current active path".[10] IOS XR does not list it as a step at all: a separate third part of its algorithm decides whether a best-path change "can be suppressed".[9] FRR calls it the "already-selected external check" and implements it with a flag, not a timestamp.[11] GoBGP compares stored timestamps.[13] - Router ID. Cisco, Junos and FRR substitute the ORIGINATOR_ID for reflected routes. GoBGP 4.11 uses the BGP ID of the session and, by default, compares router IDs only between iBGP paths.[8][10][11][13]
- The last step. FRR's user documentation says "Prefer the route received from the peer with the higher transport layer address". The code in bgpd/bgp_route.c does the opposite: a positive
sockunion_cmp()result logs "loses to ... due to Neighbor IP comparison", so the lower address wins, as in RFC 4271, Cisco, Junos, Arista EOS and our GoBGP lab.[11][1][12]
Cisco also documents how IOS walks the list: "BGP assigns the first valid path as the current best path. BGP then compares the best path with the next path in the list, until BGP reaches the end of the list of valid paths."[8] Remember that sentence; it matters for MED below.
The lab: every step on one GoBGP router
To see each step in isolation we built one real BGP router, GoBGP 4.11 (r1, AS 65001), and connected seven raw BGP speakers written in Python: three eBGP peers (E1 and E3 in AS 65010, E2 in AS 65020), three iBGP peers (I1, I2, I3) and an eBGP observer X that shows what r1 advertises, i.e. its best path. The speakers send hand-built UPDATEs, so we control every attribute byte; every test uses its own /24 and the paths differ in one attribute.[17]
One limitation up front: GoBGP has no IGP, so it cannot show the IGP-metric step, and its comparator has no weight and no CLUSTER_LIST step.[13] We cover those with real IOS XR outputs in the next section.
LOCAL_PREF beats a shorter AS_PATH
E1 advertises 10.16.1.0/24 with AS_PATH 65010. Then iBGP peer I1 advertises the same prefix with a three-AS path but LOCAL_PREF 200. The longer path wins, because LOCAL_PREF is checked first:
r1# gobgp global rib 10.16.1.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.1.0/24 127.0.2.177 65010 65030 65040 00:00:02 [{Origin: i} {LocalPref: 200}]
* 10.16.1.0/24 127.0.2.174 65010 00:00:03 [{Origin: i}]
GoBGP prints no LOCAL_PREF for the eBGP path because none was received; RFC 4271 does not allow LOCAL_PREF on eBGP sessions, and Cisco treats a missing value as 100.[1][8] At the end of the run I1 withdrew its path, and r1 fell back to E1 immediately, which is all a LOCAL_PREF backup design relies on:
r1# gobgp global rib 10.16.1.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.1.0/24 127.0.2.174 65010 00:00:53 [{Origin: i}]
Locally originated routes
For 10.16.2.0/24, E2 and I1 send the route first, then r1 adds the same prefix itself with gobgp global rib add. The local path wins over both, even over I1's path with an empty AS_PATH and ORIGIN IGP. GoBGP marks its locally added route as ORIGIN ?, so the local-origin step decided before ORIGIN was even looked at:
r1# gobgp global rib 10.16.2.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.2.0/24 0.0.0.0 00:00:02 [{Origin: ?}]
* 10.16.2.0/24 127.0.2.177 00:00:04 [{Origin: i} {LocalPref: 100}]
* 10.16.2.0/24 127.0.2.175 65020 00:00:04 [{Origin: i}]
AS_PATH length, and why an AS_SET counts as one
Test T3 is the textbook case: a one-AS path beats a two-AS path even though the two-AS path is older. Test T3b is the one that catches people out. E1 sends 65010 {65031,65032,65033}, an AS_SEQUENCE of one AS followed by an AS_SET of three; E2 sends a plain sequence of three ASes. Four AS numbers beat three, because "an AS_SET counts as 1":[1][8]
r1# gobgp global rib 10.16.3.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.3.0/24 127.0.2.175 65020 00:00:02 [{Origin: i}]
* 10.16.3.0/24 127.0.2.174 65010 65031 00:00:04 [{Origin: i}]
r1# gobgp global rib 10.16.13.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.13.0/24 127.0.2.174 65010 {65031,65032,65033} 00:00:02 [{Origin: i}]
* 10.16.13.0/24 127.0.2.175 65020 65021 65022 00:00:03 [{Origin: i}]
AS_SETs appear on aggregates (part 7 decoded them on the wire). RFC 9774 (May 2025) deprecates them, saying a speaker MUST NOT advertise them, but the counting rule is still in every implementation's best-path code.[18]
ORIGIN
E1's path is older but carries ORIGIN INCOMPLETE (?, typical for redistributed routes); E2's newer path carries IGP. With equal AS_PATH lengths, IGP wins:[1]
r1# gobgp global rib 10.16.4.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.4.0/24 127.0.2.175 65020 00:00:02 [{Origin: i}]
* 10.16.4.0/24 127.0.2.174 65010 00:00:04 [{Origin: ?}]
MED: only inside one neighbor AS
The first pair below comes from two peers in the same neighbor AS 65010: MED 10 beats MED 50 even though the MED 50 path is older. The second pair has the same MED values from two different neighbor ASes. Now MED is not compared at all, and the decision falls through to the age of the path: the older MED 50 path wins.[1][13]
r1# gobgp global rib 10.16.5.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.5.0/24 127.0.2.176 65010 00:00:02 [{Origin: i} {Med: 10}]
* 10.16.5.0/24 127.0.2.174 65010 00:00:03 [{Origin: i} {Med: 50}]
r1# gobgp global rib 10.16.15.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.15.0/24 127.0.2.174 65010 00:00:04 [{Origin: i} {Med: 50}]
* 10.16.15.0/24 127.0.2.175 65020 00:00:02 [{Origin: i} {Med: 10}]
That second result surprises people who read "lowest MED wins" without the condition. Part 13 of this series covers MED in depth, including always-compare-med and the arrival-order effect.
eBGP over iBGP
I2 (BGP ID 10.0.0.70, the lowest in the lab) sends 10.16.6.0/24 first; E2 sends an identical path 1.5 s later. The newer eBGP path wins at step d, long before router IDs or age could matter:
r1# gobgp global rib 10.16.6.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.6.0/24 127.0.2.175 65020 00:00:02 [{Origin: i}]
* 10.16.6.0/24 127.0.2.178 65020 00:00:03 [{Origin: i} {LocalPref: 100}]
The oldest eBGP path, and how a community change flips it
Now the step most summaries leave out. E2 (BGP ID 10.0.0.75) sends 10.16.7.0/24 first; E1 (BGP ID 10.0.0.74, lower) sends an equal path 1.5 s later. These are the five UPDATEs the two speakers sent, in order:
33.414 E2 tx type=2 len=51 ORIGIN=0 | AS_PATH=65020 65030 | NH=127.0.2.175 | NLRI 10.16.7.0/24
34.915 E1 tx type=2 len=51 ORIGIN=0 | AS_PATH=65010 65030 | NH=127.0.2.174 | NLRI 10.16.7.0/24
36.959 E2 tx type=2 len=51 ORIGIN=0 | AS_PATH=65020 65030 | NH=127.0.2.175 | NLRI 10.16.7.0/24 re-send identical
39.003 E2 tx type=2 len=58 ORIGIN=0 | AS_PATH=65020 65030 | NH=127.0.2.175 | COMM[fl=0xc0 len=4]=65020:1 {c00804fdfc0001} | NLRI 10.16.7.0/24 re-send + community
41.049 E1 tx type=2 len=58 ORIGIN=0 | AS_PATH=65010 65030 | NH=127.0.2.174 | COMM[fl=0xc0 len=4]=65010:1 {c00804fdf20001} | NLRI 10.16.7.0/24 re-send + community
After the second UPDATE the older E2 path is best, although E1 has the lower router ID (the Age column shows E2's path 2 s older):
r1# gobgp global rib 10.16.7.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.7.0/24 127.0.2.175 65020 65030 00:00:04 [{Origin: i}]
* 10.16.7.0/24 127.0.2.174 65010 65030 00:00:02 [{Origin: i}]
The identical re-send from E2 changed nothing: GoBGP kept the original timestamp. But when E2 re-sent the route with a community added, the path was replaced, its age reset, and E1's path became the older one and the best path:
r1# gobgp global rib 10.16.7.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.7.0/24 127.0.2.174 65010 65030 00:00:06 [{Origin: i}]
* 10.16.7.0/24 127.0.2.175 65020 65030 00:00:02 [{Origin: i} {Communities: 65020:1}]
The observer X saw each of those decisions as a new UPDATE from r1: first the path via 65020, then via 65010 after E2's community change, then via 65020 again after E1's own change:
33.414 X rx type=2 len=55 ORIGIN=0 | AS_PATH=65001 65020 65030 | NH=127.0.2.171 | NLRI 10.16.7.0/24
39.004 X rx type=2 len=55 ORIGIN=0 | AS_PATH=65001 65010 65030 | NH=127.0.2.171 | NLRI 10.16.7.0/24
41.050 X rx type=2 len=62 ORIGIN=0 | AS_PATH=65001 65020 65030 | NH=127.0.2.171 | COMM[fl=0xc0 len=4]=65020:1 {c00804fdfc0001} | NLRI 10.16.7.0/24
So an attribute change on one path (a new community from an upstream, a prepend added and removed) can move traffic to another exit, even though nothing changed on that other path. Phase B of the lab repeated the test with GoBGP's external-compare-router-id, the equivalent of bgp bestpath compare-routerid on Cisco and FRR and path-selection external-router-id on Junos:[8][10][11][13]
[global.route-selection-options.config] external-compare-router-id = true
E1, the lower router ID, now won as soon as it arrived and stayed best through every re-send:
r1# gobgp global rib 10.16.7.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.7.0/24 127.0.2.174 65010 65030 00:00:02 [{Origin: i}]
* 10.16.7.0/24 127.0.2.175 65020 65030 00:00:03 [{Origin: i}]
Which behaviour is better is a design choice. The age rule reduces churn: a new path does not displace a working one just because its router ID is lower, which is exactly what RFC 5004 wanted.[3] The router-ID rule makes the result reproducible: two routers with the same paths choose the same exit regardless of history, which helps troubleshooting and predictable traffic engineering. FRR's documentation names the cost: "a few or even one lowest-ID router may attract all traffic to otherwise-equal paths".[11]
Router ID and neighbor address
Between iBGP paths age plays no role. I1 (ID 10.0.0.77) and I2 (ID 10.0.0.70) send identical paths, in both orders. I2 wins both times:
r1# gobgp global rib 10.16.8.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.8.0/24 127.0.2.178 65040 00:00:02 [{Origin: i} {LocalPref: 100}]
* 10.16.8.0/24 127.0.2.177 65040 00:00:04 [{Origin: i} {LocalPref: 100}]
r1# gobgp global rib 10.16.18.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.18.0/24 127.0.2.178 65040 00:00:03 [{Origin: i} {LocalPref: 100}]
* 10.16.18.0/24 127.0.2.177 65040 00:00:02 [{Origin: i} {LocalPref: 100}]
For the very last step we gave I3 (address 127.0.2.181) the same BGP ID as I1 (127.0.2.177). Router IDs tie, and the lower peer address wins, although I3's path is older:[1]
r1# gobgp global rib 10.16.9.0/24 -a ipv4
Network Next Hop AS_PATH Age Attrs
*> 10.16.9.0/24 127.0.2.177 65040 00:00:02 [{Origin: i} {LocalPref: 100}]
* 10.16.9.0/24 127.0.2.181 65040 00:00:04 [{Origin: i} {LocalPref: 100}]
Duplicate router IDs inside one AS sound exotic, but the same tie happens legitimately when two sessions run to the same router, a case IOS XR documents explicitly: "It is also possible to have two BGP sessions with the same peer router".[9]
Steps the lab cannot show: real IOS XR outputs
For weight, the IGP metric and the ORIGINATOR_ID substitution we use the kazulog.info labs: Cisco XRd routers running IOS XR 26.1.1, with configuration, show output and packet captures published for every step. We downloaded the files and quote them unchanged (shortened to the relevant lines).[14]
Weight beats LOCAL_PREF. R1 sets weight 200 on everything from R4 and LOCAL_PREF 200 on 192.168.5.0/24 from R6. Path #2 (weight 200, localpref 100) stays best over Path #4 (localpref 200). Paths #3 and #5 are the received-only pre-policy copies kept by soft reconfiguration; they never take part in the selection:[14]
RP/0/RP0/CPU0:R1#show bgp 192.168.5.0/24
Paths: (5 available, best #2)
Path #1: Received by speaker 0
65002 65003, (received & used)
10.0.0.2 (metric 3) from 10.0.0.2 (10.0.0.2)
Origin IGP, localpref 100, valid, internal
Path #2: Received by speaker 0
65002 65003
10.1.4.4 from 10.1.4.4 (10.0.0.4)
Origin IGP, localpref 100, weight 200, valid, external, best, group-best
Origin-AS validity: (disabled)
Path #3: Received by speaker 0
65002 65003, (received-only)
10.1.4.4 from 10.1.4.4 (10.0.0.4)
Origin IGP, localpref 100, valid, external
Origin-AS validity: (disabled)
Path #4: Received by speaker 0
65004 65003
10.1.6.6 from 10.1.6.6 (10.0.0.6)
Origin IGP, localpref 200, valid, external, group-best
Origin-AS validity: (disabled)
Path #5: Received by speaker 0
65004 65003, (received-only)
10.1.6.6 from 10.1.6.6 (10.0.0.6)
Origin IGP, localpref 100, valid, external
Origin-AS validity: (disabled)
RP/0/RP0/CPU0:R1#show bgp 192.168.6.0/24
Paths: (1 available, best #1)
Path #1: Received by speaker 0
65004, (received & used)
10.1.6.6 from 10.1.6.6 (10.0.0.6)
Origin IGP, metric 0, localpref 100, valid, external, best, group-best
Origin-AS validity: (disabled)
In the same lab, setting the weight of a locally originated network to 0 did not make the received path win: the local path still won at the local-origin step and on AS_PATH length 0 against 1. The received path only won with a weight above 32768 (40000 in STEP 6), and a per-neighbor weight then moved every prefix from that neighbor, not just one.[14]
The oldest path beats the lower router ID on IOS XR too. In the as-path lab, R5 has two eBGP paths to 192.168.1.0/24 of equal length after a prepend is removed again. Path #1 comes from router ID 10.0.0.3, path #2 from 10.0.0.4, and path #2 is best: adding and removing the prepend re-advertised the path via R3, making it the newer one, and IOS XR kept the older path.[14][9]
RP/0/RP0/CPU0:R5#show bgp 192.168.1.0/24
Last Modified: Sep 28 14:32:38.023 for 00:12:32
Paths: (2 available, best #2)
Path #1: Received by speaker 0
65002 65001, (received & used)
10.3.5.3 from 10.3.5.3 (10.0.0.3)
Origin IGP, localpref 100, valid, external, group-best
Origin-AS validity: (disabled)
Path #2: Received by speaker 0
65003 65001, (received & used)
10.4.5.4 from 10.4.5.4 (10.0.0.4)
Origin IGP, localpref 100, valid, external, best, group-best
Origin-AS validity: (disabled)
RP/0/RP0/CPU0:R5#show bgp 192.168.2.0/24
Last Modified: Sep 28 14:32:38.023 for 00:12:33
Paths: (2 available, best #2)
Path #1: Received by speaker 0
65002 65001, (received & used)
10.3.5.3 from 10.3.5.3 (10.0.0.3)
Origin IGP, localpref 100, valid, external, group-best
ORIGINATOR_ID replaces the router ID. In the add-path lab R4 receives two paths for 192.168.100.0/24 from the same route reflector, 10.0.0.1. The value in parentheses is not the neighbor's router ID but the originator: 10.0.0.2 against 10.0.0.3. Both paths have IGP metric 3 to their next hops, and the lower originator wins. The "multipath" marks come from maximum-paths ibgp 2 with bgp bestpath as-path multipath-relax in R4's configuration, the "Received Path ID" values from ADD-PATH:[14][2][5]
RP/0/RP0/CPU0:R4#show bgp 192.168.100.0/24
Paths: (2 available, best #1)
Path #1: Received by speaker 0
65002, (received & used)
10.0.0.2 (metric 3) from 10.0.0.1 (10.0.0.2)
Origin IGP, metric 0, localpref 100, valid, internal, best, group-best, multipath
Received Path ID 1, Local Path ID 1, version 47
Originator: 10.0.0.2, Cluster list: 10.0.0.1
Path #2: Received by speaker 0
65003, (received & used)
10.0.0.3 (metric 3) from 10.0.0.1 (10.0.0.3)
Origin IGP, metric 0, localpref 100, valid, internal, multipath
Received Path ID 3, Local Path ID 0, version 0
Originator: 10.0.0.3, Cluster list: 10.0.0.1
The IGP metric step itself shows up in the same output as (metric 3) next to the next hop. When two iBGP paths differ there, the lower metric wins, which is the "hot potato" behaviour that makes every router leave the AS by its nearest exit.[8][9]
Real Internet paths: RouteViews and FRR in Sydney
A lab shows that the rules work; a route server shows which rules actually decide. We logged in to route-views.routeviews.org, a Cisco ASR1000 running IOS XE 03.16.10.S (IOS 15.5(3)S10), on 5 December 2026 at 00:18 UTC and read four well-known prefixes.[15] The router installs one best path per prefix (Maximum path: 1):
show ip bgp 8.8.8.0/24 bestpath
BGP routing table entry for 8.8.8.0/24, version 1546362268
Paths: (15 available, best #12, table default)
Not advertised to any peer
Refresh Epoch 1
101 15169
209.124.176.223 from 209.124.176.223 (209.124.176.224)
Origin IGP, localpref 100, valid, external, best
Community: 101:20400 101:22200 101:24100
path 7F1549021BD0 RPKI State valid
rx pathid: 0, tx pathid: 0x0
The table view shows the columns we need to rule out the first steps: weight 0 on every path, no LOCAL_PREF printed (localpref 100 in the detailed view), ten paths with a two-AS AS_PATH:
show ip bgp 8.8.8.0/24 longer-prefixes
BGP table version is 1567826112, local router ID is 128.223.51.103
Network Next Hop Metric LocPrf Weight Path
V* 8.8.8.0/24 77.39.192.30 0 20912 15169 i
V* 140.192.8.16 0 20130 23352 15169 i
V* 193.0.0.56 0 3333 1257 15169 i
V* 12.0.1.63 0 7018 15169 i
V* 64.71.137.241 0 6939 15169 i
V* 132.198.255.253 0 1351 214292 15169 i
V* 208.51.134.254 0 0 3549 3356 15169 i
V* 4.68.4.46 0 0 3356 15169 i
V* 217.192.89.50 0 3303 15169 i
V* 94.142.247.3 0 8283 15169 i
V* 37.139.139.17 0 0 57866 15169 i
V*> 209.124.176.223 0 101 15169 i
V* 114.31.199.16 0 4826 15169 i
V* 91.218.184.60 0 49788 12552 15169 i
V* 202.232.0.2 0 2497 15169 i
The next hops are reached through static routes with metric 0, so the IGP-metric step ties too:
show ip route 209.124.176.223
Routing entry for 209.124.176.223/32
Known via "static", distance 1, metric 0
Routing Descriptor Blocks:
* 128.223.51.1
Route metric is 0, traffic share count is 1
Our script re-applied the steps to the printed paths. LOCAL_PREF left 15, AS_PATH length 10; ORIGIN, MED (all ten from different neighbor ASes, so MED is never compared), eBGP and IGP metric left all 10. The lowest router ID among them is 4.69.184.201 (the AS 3356 path, #8), not the chosen AS 101 path with router ID 209.124.176.224. The only Cisco step between the IGP metric and the router ID is the oldest-path rule, so by elimination the age of the path decided. The router does not print ages, so this is an inference from the documented rules, and it holds for three of the four prefixes:
Other RouteViews collectors run FRR, and FRR prints the reason next to the best path.[11] route-views.sydney.routeviews.org (FRRouting 10.5.1 (route-views.sydney)) at 00:30 UTC gives the answer directly:[16]
show bgp ipv4 unicast 8.8.8.0/24
BGP routing table entry for 8.8.8.0/24, version 61033
Paths: (14 available, best #1, table default)
Not advertised to any peer
7594 15169
45.127.173.66 from 45.127.173.66 (8.245.132.42)
Origin IGP, valid, external, best (Older Path), rpki validation-state: valid
Community: 7594:1004 7594:32000
Last update: Thu Dec 3 19:16:57 2026
16552 15169
45.127.173.71 from 45.127.173.71 (46.31.238.25)
Origin IGP, valid, external, rpki validation-state: valid
Community: 16552:9200 16552:10200 16552:20036 16552:40016
Last update: Thu Dec 3 19:16:57 2026
8888 15169
45.127.173.20 from 45.127.173.20 (100.111.100.1)
Origin IGP, valid, external, rpki validation-state: valid
Community: 8888:15169
Last update: Thu Dec 3 19:16:57 2026
132847 15169
45.127.172.152 from 45.127.172.152 (103.74.171.30)
Origin IGP, valid, external, rpki validation-state: valid
Community: 65500:129
Last update: Thu Dec 3 19:16:57 2026
148968 15169
45.127.172.73 from 45.127.172.67 (103.182.41.1)
Origin IGP, valid, external, rpki validation-state: valid
Last update: Thu Dec 3 19:17:48 2026
show bgp ipv4 unicast 1.1.1.0/24
BGP routing table entry for 1.1.1.0/24, version 4873
Paths: (17 available, best #1, table default)
Not advertised to any peer
13335, (aggregated by 13335 10.34.8.168)
45.127.172.154 from 45.127.172.154 (108.162.247.2)
Origin IGP, valid, external, atomic-aggregate, best (AS Path), rpki validation-state: valid
Large Community: 13335:10000026:0
Last update: Thu Dec 3 19:16:57 2026
7594 13335, (aggregated by 13335 10.34.8.168)
45.127.172.154 from 45.127.173.66 (8.245.132.42)
Origin IGP, valid, external, atomic-aggregate, rpki validation-state: valid
Community: 7594:1004 7594:1005 7594:32000
Large Community: 13335:10000026:0
Last update: Thu Dec 3 19:16:56 2026
For 1.1.1.0/24 the path straight from AS 13335 wins on AS Path. For 8.8.8.0/24, 9.9.9.0/24 and 193.0.0.0/21 FRR says Older Path. One detail is worth knowing: in all three cases the winning path also has the lowest router ID of the tied paths (8.245.132.42 and 10.255.15.67), and many paths show the same Last update second, 3 December 19:16:57. Our reading is that the paths were first compared down to the router ID when the sessions came up together, and since then FRR's already-selected rule keeps the incumbent and is reported as the reason, because it fires before the router-ID check. The Cisco route server shows the other side of the same rule: its incumbents are not the lowest router IDs, so they must have been there first.
Why comparison order matters: MED and deterministic grouping
Pairwise "best so far" selection only works if the comparison is transitive: if A beats B and B beats C, A must beat C. MED breaks that, because it is only compared inside one neighbor AS. IOS XR says it plainly: "the comparison operation is not transitive".[9] A three-path example, with router ID as the last tie-breaker:
A beats B (router ID), B beats C (router ID), but C beats A (MED, same neighbor AS 100). Comparing the paths one after another, as Cisco IOS does by default, gives a result that depends on the order: A then B then C gives C, A then C then B gives B, B then A then C gives C, B then C then A gives A, C then A then B gives B, C then B then A gives A. Every path can win. The fix is to group the paths by neighbor AS, choose the best inside each group, and compare only the group winners: C wins AS 100, B is alone in AS 200, and B beats C. IOS XR always does this ("The paths are partitioned into groups such that within each group the MED can be compared among all paths"), Junos does it unless you configure path-selection cisco-non-deterministic, and Cisco IOS and FRR do it with bgp deterministic-med.[9][10][11][8] In part 13 we measured the effect live: with three paths from two ASes and no deterministic MED, GoBGP picked three different winners across 18 runs, one of them a path that RFC 4271 says should lose.[7] RFC 3345 describes the network-wide version of the problem, persistent route oscillation with route reflectors or confederations and MED.[7]
Multipath and ADD-PATH: when one best path is not the end
Best path selection always produces exactly one best path, but two features let BGP use or advertise more.
Multipath (maximum-paths) installs several paths in the forwarding table when they tie down to the IGP-metric step; Cisco places the multipath decision exactly there, and Junos says a path is an equal-cost path "if a tie-break is performed after the previous step".[8][10] By default the candidates must also have the same AS_PATH; bgp bestpath as-path multipath-relax (IOS XR, FRR) only requires the same length.[11][14] The kazulog multipath lab shows the rule on IOS XR: with maximum-paths ebgp 2 the two paths with the identical AS_PATH 65001 65004 become multipath, and the third path via 65003 65004 does not:[14]
RP/0/RP0/CPU0:R4#show bgp 192.168.6.0/24
Paths: (3 available, best #1)
Path #1: Received by speaker 0
65001 65004, (received & used)
10.1.4.1 from 10.1.4.1 (10.0.0.1)
Origin IGP, localpref 100, valid, external, best, group-best, multipath
Origin-AS validity: (disabled)
Path #2: Received by speaker 0
65001 65004, (received & used)
10.2.4.2 from 10.2.4.2 (10.0.0.2)
Origin IGP, localpref 100, valid, external, multipath
Origin-AS validity: (disabled)
Path #3: Received by speaker 0
65003 65004, (received & used)
10.4.5.5 from 10.4.5.5 (10.0.0.5)
Origin IGP, localpref 100, valid, external, group-best
Origin-AS validity: (disabled)
RP/0/RP0/CPU0:R4#show bgp 192.168.7.0/24
Paths: (1 available, best #1)
In the same lab, setting LOCAL_PREF 90 on one member removed it from the set while the best path stayed the same, and combining eBGP and iBGP paths (maximum-paths eibgp) on plain IPv4 made traffic loop between R1 and R3, the case Cisco's guide warns about when traffic "may loop between the PE devices".[14]
ADD-PATH (RFC 7911) does not change the decision either; it lets a speaker advertise more than one path per prefix, each tagged with a Path Identifier.[5] A route reflector normally reflects only its best path, which hides the alternatives from its clients. With ADD-PATH, the kazulog R4 above receives both paths with Path IDs 1 and 3 and can use them for multipath or fast failover.[14]
Configuration knobs that change the algorithm
Configuration examples from vendor documentation; only the GoBGP lines were run in our lab. Configure them consistently on every router in the AS, otherwise routers disagree about the best path; Cisco explicitly warns that always-compare-med on only part of the AS can cause routing loops.[8]
! Cisco IOS / IOS XE router bgp 65001 bgp bestpath compare-routerid ! skip the oldest-path rule bgp deterministic-med ! group by neighbor AS before comparing bgp always-compare-med ! compare MED across neighbor ASes (whole AS!) bgp bestpath med missing-as-worst ! missing MED = worst, not 0 bgp bestpath as-path ignore ! skip the AS_PATH length step maximum-paths 2 ! eBGP multipath ! Cisco IOS XR router bgp 65001 bgp bestpath compare-routerid bgp bestpath med always bgp bestpath as-path multipath-relax address-family ipv4 unicast maximum-paths ebgp 2 # Junos set protocols bgp path-selection external-router-id set protocols bgp path-selection always-compare-med set protocols bgp group transit multipath ! FRR router bgp 65001 bgp bestpath compare-routerid bgp deterministic-med bgp bestpath as-path multipath-relax # GoBGP (run in our lab, phase B) [global.route-selection-options.config] external-compare-router-id = true
Sources for the syntax: Cisco 13753 and the IOS XR BGP configuration guide, the Junos path selection topic, the FRR documentation and the kazulog IOS XR configurations.[8][9][10][11][14]
Troubleshooting: why is this path not best?
| Symptom | Likely cause | What to check |
|---|---|---|
| A path is in the table but never considered | Unreachable NEXT_HOP, received-only copy, IOS XR maximum MED | show ip route <next-hop>; ignore received-only entries (soft reconfiguration copies) |
| A longer AS_PATH wins | Weight or LOCAL_PREF set by policy, or an AS_SET counted as 1 | Weight and LocPrf columns; inbound route-maps or route-policies |
| The lower MED loses | Different neighbor AS (MED skipped) or arrival order without deterministic MED | First AS of each AS_PATH; bgp deterministic-med |
| The best path moves although nothing changed on it | Oldest-path rule: the other path was re-advertised | Last-modified time per path; FRR best (Older Path); consider compare-routerid |
| Two routers in one AS pick different exits | IGP metric (hot potato) or age-based tie-break | (metric N) next to the next hop; compare router IDs and ages |
| Reflected paths tie-break unexpectedly | ORIGINATOR_ID used instead of router ID; GoBGP ignores it | Originator: and Cluster list: lines |
| Traffic loops with multipath | eiBGP multipath on plain IP | Use it only where labels carry the packet to the remote PE (L3VPN) |
The fastest method is to read the detailed prefix output and walk the list from the top for the best path and the path you expected, stopping at the first attribute that differs. FRR does the walk for you and prints the reason; debug bgp bestpath <prefix> also logs every "wins over ... due to" comparison.[11]
FAQ
What is the BGP best path selection order?
On Cisco IOS the order is: highest weight, highest LOCAL_PREF, locally originated, shortest AS_PATH, lowest ORIGIN (IGP, EGP, incomplete), lowest MED among paths from the same neighbor AS, eBGP over iBGP, lowest IGP metric to the next hop, multipath check, oldest eBGP path, lowest router ID (ORIGINATOR_ID if present), shortest CLUSTER_LIST and lowest neighbor address. Paths with an unreachable next hop are not candidates at all. Junos, IOS XR and FRR use nearly the same order with small differences at the edges.
Does BGP prefer the lowest router ID?
Only late, and often not at all for eBGP paths. Before the router-ID step Cisco, Junos and FRR keep the oldest (already selected) external path, a rule based on RFC 5004 that avoids churn. In our lab the path from router ID 10.0.0.75 stayed best over 10.0.0.74 because it arrived first, and on the RouteViews route server the best paths for 8.8.8.0/24, 1.1.1.0/24 and 9.9.9.0/24 were not the ones with the lowest router ID. bgp bestpath compare-routerid (Cisco, FRR) or path-selection external-router-id (Junos) turns the age rule off.
Is weight part of the BGP standard?
No. Weight is a Cisco-specific, router-local value that is never sent in an UPDATE. Cisco IOS, IOS XR and FRR check it first, before LOCAL_PREF. Locally originated routes get 32768 on Cisco and received routes 0. Junos has no weight; its first comparison is the route preference used to choose between protocols.
Why is MED not compared between my two providers?
Because RFC 4271 says MED is only comparable between routes learned from the same neighboring AS, taken from the first AS in the AS_PATH. Two transit providers are two neighbor ASes, so their MEDs are skipped and the decision moves to the next step. You can force a comparison with always-compare-med, but it must be configured on every router in the AS.
What does deterministic MED change?
It groups the paths by neighbor AS, picks the best path inside each group (where MED is comparable) and only then compares the group winners. Without it, Cisco IOS compares paths in list order, and because MED makes the comparison non-transitive the result can depend on arrival order. IOS XR always groups, Junos groups by default, and Cisco IOS and FRR need bgp deterministic-med on all routers.
How do I see why a path was chosen?
FRR prints the reason next to the best path, for example 'best (Older Path)' or 'best (AS Path)', and in JSON as selectionReason; debug bgp bestpath logs every comparison. On Cisco IOS and IOS XR you read the attributes of every path and walk the steps yourself; IOS XR marks group-best and multipath paths. GoBGP marks the best path with *> but does not print a reason.
Is the best path the only path BGP uses?
By default yes: one best path is installed and advertised. BGP multipath (maximum-paths) installs several paths that tie down to the IGP-metric step, and ADD-PATH (RFC 7911) advertises more than one path per prefix with a path identifier. Neither changes which path is best.
How we tested
All GoBGP output is real GoBGP 4.11 output from router r1 on 127.0.2.171 (port 10179), run on 5 December 2026 between 01:22 and 01:25 CET. The seven peers are our own Python BGP sessions that send hand-built UPDATEs and record every byte r1 sends back. Phase A uses defaults; phase B sets external-compare-router-id. RouteViews output was captured read-only on 5 December 2026 (route-views at 00:18-00:19 UTC, route-views.sydney at 00:30 UTC) and analysed with our own scripts; the oldest-path conclusion for the Cisco server is an inference by elimination and is stated as such. The IOS XR outputs come from the published kazulog.info labs. Vendor configurations are documentation examples.
Series hub: BGP in 26 Parts: From EGP to EVPN
Previous: BGP CLUSTER_LIST: How Route Reflector Clusters Avoid Loops
Next: BGP Outbound Traffic Engineering: How to Control Where Your Traffic Leaves (100% Your Decision) (coming soon)
References
[1] Y. Rekhter, T. Li, S. Hares (Eds.), RFC 4271: A Border Gateway Protocol 4 (BGP-4), January 2006: s.9.1, 9.1.1, 9.1.2, 9.1.2.2.
[2] T. Bates, E. Chen, R. Chandra, RFC 4456: BGP Route Reflection, April 2006: s.9.
[3] E. Chen, S. Sangli, RFC 5004: Avoid BGP Best Path Transitions from One External to Another, September 2007.
[4] D. McPherson, K. Patel, RFC 4277: Experience with the BGP-4 Protocol, January 2006: s.7.1.4.
[5] D. Walton, A. Retana, E. Chen, J. Scudder, RFC 7911: Advertisement of Multiple Paths in BGP, July 2016.
[6] P. Mohapatra et al., RFC 7311: The Accumulated IGP Metric Attribute for BGP, August 2014: s.4.
[7] RFC 3345: Border Gateway Protocol (BGP) Persistent Route Oscillation Condition, August 2002; Network freak, BGP MED: always-compare-med and deterministic-med (part 13 lab).
[8] Cisco, Select BGP Best-path Algorithm (Document 13753), read 5 December 2026.
[9] Cisco, BGP Configuration Guide for Cisco NCS 5500, IOS XR 7.2.x: BGP Best Path Algorithm (Comparing Pairs of Paths, Order of Comparisons, Best Path Change Suppression); the same sections appear in the IOS XR 26.x NCS 5500 and Cisco 8000 guides, read 5 December 2026.
[10] Juniper Networks / HPE, Junos OS BGP Overview: Understanding BGP Path Selection, read 5 December 2026.
[11] FRRouting, BGP documentation, Route Selection and source bgpd/bgp_route.c (path comparison, reason strings), master branch, read 5 December 2026.
[12] Arista Networks, EOS 4.37.0F User Manual: Border Gateway Protocol, Best-path Selection, read 5 December 2026.
[13] GoBGP v4.11 source, internal/pkg/table/destination.go (insertSort, compareByAge, compareByRouterID, compareByNeighborAddress), read 5 December 2026.
[14] kazulog.info, Cisco XRd IOS XR 26.1.1 BGP labs: weight, local-preference, origin, as-path, multipath, add-path; show and configuration files downloaded 5 December 2026.
[15] University of Oregon RouteViews, route-views.routeviews.org (telnet, user rviews): show ip bgp, longer-prefixes, bestpath, show ip route, 5 December 2026 00:18-00:19 UTC.
[16] RouteViews, route-views.sydney.routeviews.org (FRRouting 10.5.1): show bgp ipv4 unicast, 5 December 2026 00:30 UTC.
[17] Network freak lab: GoBGP 4.11 router r1 and raw Python BGP speakers on 127.0.2.171-181, phases A and B, 5 December 2026, 01:22-01:25 CET. Configs, logs and every UPDATE are kept with the article sources.
[18] W. Kumari, K. Sriram, L. Hannachi, J. Haas, RFC 9774: Deprecation of AS_SET and AS_CONFED_SET in BGP, May 2025.
Figures 1-7: Network freak, drawn from the sources above and our lab.
Try it: BGP Route Lookup: origin AS, AS paths and RPKI check - look up any prefix and see the paths that carry it, free and in your browser.
Related reading
- How BGP Best-Path Selection Picks a Route
- BGP Local Preference: Primary/Backup and Transit Tiers
- BGP MED: always-compare-med and deterministic-med
- BGP Weight as Cisco's Local-Only Path Preference
- How to Read a Real BGP Table Entry on a Public Cisco Route Server
- BGP ORIGINATOR_ID: How Route Reflectors Stop Loops
- BGP CLUSTER_LIST: How Route Reflector Clusters Avoid Loops
Comments
Post a Comment