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.

#AttributeRule
1WeightHigher wins (Cisco-proprietary, local to the router)
2Local PreferenceHigher wins (AS-wide)
3Locally originatedPrefer routes originated by this router (network / redistribute over aggregate)
4AS-PATHShorter wins (fewer AS to cross)
5OriginIGP (i) > EGP (e) > Incomplete (?)
6MEDLower wins (by default only among routes from the same neighboring AS)
7eBGP over iBGPPrefer an eBGP-learned path over an iBGP-learned path
8Next-hop IGP metricPrefer the path with the lowest IGP metric to the BGP next-hop
9MultipathIf multipath is configured, install multiple equal paths for load sharing
10AgePrefer the oldest (most stable) eBGP route
11Router IDPrefer the lowest Router ID (or lowest Originator ID for reflected routes)
12Cluster ListPrefer the shortest Cluster List
13Neighbor IPPrefer 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-med changes this).
  • Origin (step 5) prefers i over e over ?.
  • 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

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

Q3 — At the Origin step, which is most preferred?

A) Incomplete (?)
B) EGP (e)
C) IGP (i)
D) All equal

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

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