18 BGP Best-Path Algorithm
BGP does not use a single metric. To choose the single best path to a destination, it evaluates a list of attributes in a fixed order, stopping at the first one that breaks the tie. This note is the reference for that ordered process; each attribute has its own note.
Preconditions
Before a route can even enter best-path comparison, its next-hop must be reachable. A route whose next-hop cannot be resolved is invalid and is not considered.
The ordered algorithm
Attributes are evaluated top to bottom. The first step that distinguishes the candidates decides the winner.
| # | Attribute | Rule |
|---|---|---|
| 1 | Weight | Higher wins (Cisco-proprietary, local to the router) |
| 2 | Local Preference | Higher wins (AS-wide) |
| 3 | Locally originated | Prefer routes originated by this router (network / redistribute over aggregate) |
| 4 | AS-PATH | Shorter wins (fewer AS to cross) |
| 5 | Origin | IGP (i) > EGP (e) > Incomplete (?) |
| 6 | MED | Lower wins (by default only among routes from the same neighboring AS) |
| 7 | eBGP over iBGP | Prefer an eBGP-learned path over an iBGP-learned path |
| 8 | Next-hop IGP metric | Prefer the path with the lowest IGP metric to the BGP next-hop |
| 9 | Multipath | If multipath is configured, install multiple equal paths for load sharing |
| 10 | Age | Prefer the oldest (most stable) eBGP route |
| 11 | Router ID | Prefer the lowest Router ID (or lowest Originator ID for reflected routes) |
| 12 | Cluster List | Prefer the shortest Cluster List |
| 13 | Neighbor IP | Prefer the route from the neighbor with the lowest IP address |
Reading the order sensibly
A few groupings make the list easier to remember:
- Steps 1 to 3 are about local and locally-originated preference: Weight (this router), Local Preference (this AS), and routes this router itself originated.
- Steps 4 to 6 are the classic path attributes: AS-PATH, Origin, MED.
- Step 7 prefers external paths over internal ones.
- Steps 8 onward are tiebreakers used when everything above is equal, ending in deterministic ties (Router ID, Cluster List, neighbor IP).
Key reminders tied to the order
- Weight comes before Local Preference, so a higher Weight on one router can override a better Local Preference.
- MED (step 6) is only compared among routes from the same neighboring AS by default (
always-compare-medchanges this). - Origin (step 5) prefers
iovereover?. - The final steps guarantee a single deterministic winner even when all real attributes tie.
Self-check
Q1 — What is the first attribute checked in best-path?
A) Local Preference
B) Weight
C) AS-PATH
D) MED
Respuesta
B is correct. Weight is checked first (higher wins). Because it is evaluated before Local Preference, a higher Weight on a router can override a better Local Preference.
- A) False — Local Preference is second, after Weight.
- C) False — AS-PATH is step 4.
- D) False — MED is step 6.
Q2 — In what order are Weight and Local Preference evaluated, and which value wins each?
A) Local Preference first, then Weight; lower wins both
B) Weight first (higher wins), then Local Preference (higher wins)
C) Weight first (lower wins), then Local Preference (lower wins)
D) They are evaluated together
Respuesta
B is correct. Weight is step 1 (higher wins), Local Preference is step 2 (higher wins). Weight being first is why it can override Local Preference.
- A) False — Weight is first, and higher (not lower) wins both.
- C) False — higher wins for both, not lower.
- D) False — they are separate, ordered steps.
Q3 — At the Origin step, which is most preferred?
A) Incomplete (
?)
B) EGP (e)
C) IGP (i)
D) All equal
Respuesta
C is correct. Origin prefers IGP (
i) over EGP (e) over Incomplete (?).
- A) False — Incomplete is the least preferred.
- B) False — EGP sits between IGP and Incomplete, not first.
- D) False — they are ranked.
Q4 — At step 7, which path is preferred?
A) iBGP over eBGP
B) eBGP over iBGP
C) The path with the higher MED
D) The path with the longer AS-PATH
Respuesta
B is correct. Step 7 prefers an eBGP-learned path over an iBGP-learned path.
- A) False — it is the other way around.
- C) False — MED (lower wins) is step 6, already passed.
- D) False — shorter AS-PATH is preferred, and that was step 4.
Q5 — What guarantees a single deterministic winner when all real attributes tie?
A) The route is dropped
B) The final tiebreakers: lowest Router ID / Originator ID, shortest Cluster List, lowest neighbor IP
C) Both routes are installed automatically
D) The oldest route is always chosen first
Respuesta
B is correct. The final steps (Router ID / Originator ID, Cluster List, neighbor IP) deterministically break any remaining tie.
- A) False — a winner is chosen, not dropped.
- C) False — installing multiple requires multipath (step 9), not a tie.
- D) False — Age (step 10) comes before the ID tiebreakers, but the ID steps are what guarantee determinism.