← Learn networking

BGP Best-Path Selection, Step by Step

5 min read

BGP does not use a single metric like OSPF's cost. Instead it runs each candidate route through an ordered list of tie-breakers, and the first step where the routes differ decides the winner. Memorise the order and the logic becomes mechanical. This article uses the standard decision sequence implemented by Cisco IOS.

In simple words

If OSPF is a map inside one city, BGP is the system that moves letters between countries. Each network (called an Autonomous System) announces "I can reach these addresses", and BGP picks which neighbour to hand your traffic to — not by shortest road, but by policy first: who the operator prefers, then by how many networks the path crosses.

The decision order

For each prefix, BGP compares the available paths step by step, stopping at the first difference:

  1. Highest weight — a Cisco-local value (default 0; routes originated locally get 32768). Never advertised to neighbours.
  2. Highest local preference — default 100. The main tool for steering outbound traffic within an AS.
  3. Locally originated — prefer routes originated on this router (via network or aggregation) over routes learned from a neighbour.
  4. Shortest AS path — fewest autonomous systems in the path.
  5. Lowest origin type — IGP (i) beats EGP (e) beats Incomplete (?).
  6. Lowest MED (Multi-Exit Discriminator) — compared only between paths from the same neighbouring AS.
  7. eBGP over iBGP — prefer a path learned from an external neighbour over one learned internally.
  8. Lowest IGP metric to the next hop — the classic "hot-potato" step: exit the AS as quickly as possible.
  9. Oldest eBGP route — prefer the path that has been stable the longest (flap damping by preference for stability).
  10. Lowest router ID — of the BGP speakers offering the path.
  11. Lowest neighbour address — the final tie-breaker.

Why the order matters more than any single step

Notice what is *not* near the top: AS path length is only step 4. A three-AS path with local preference 200 beats a one-AS path with local preference 100 every time. This surprises newcomers, but it is deliberate — the operator's policy (weight, local preference) is meant to override the internet's raw topology. Likewise MED, which many people reach for first, only matters at step 6 and only between routes from the same neighbouring AS.

Worked example: local preference decides before AS path is consulted

Your router learns 203.0.113.0/24 twice:

  • Path A via AS 64512: AS path length 3, local preference 200, origin IGP.
  • Path B via AS 64513: AS path length 1, local preference 100, origin IGP.

Step 1: weights equal (both 0). Step 2: local preference 200 vs 100 — Path A wins immediately. The shorter AS path of B is never considered. Now change the scenario: both paths have local preference 100. Step 2 ties; step 3 ties (neither locally originated); step 4 compares AS path length — Path B (length 1) wins. This is exactly how engineers steer traffic: raise local preference on the preferred exit and it overrides everything below it.

BGP: policy decides before path length
1/4
Your routerAS 645123 hopsAS 645131 hop203.0.113.0/24

Two candidate paths to 203.0.113.0/24: AS 64512 (3 hops) and AS 64513 (1 hop).

  1. Two candidate paths to 203.0.113.0/24: AS 64512 (3 hops) and AS 64513 (1 hop).
  2. Step 1 — Weight: tie.
  3. Step 2 — Local preference: 200 vs 100.
  4. Winner — policy decided before path length. Shorter, but never reached — step 4.

When MED actually decides

MED finally matters when everything above it ties. Take two paths to 203.0.113.0/24 learned from the same neighbouring AS 64512: Path X enters via your router R1 with MED 50, Path Y enters via R2 with MED 100. Weight, local preference, origin type and AS path are identical, so steps 1–5 all tie and step 6 compares MED: lower wins, so Path X. This is MED's designed purpose — the neighbouring AS is telling you which entry point into *its* network it prefers, and you honour it when you have no policy reason to do otherwise. The classic deployment: two links to the same provider, MED set lower on the higher-capacity one. Remember the two constraints that make MED so often irrelevant: it is only compared between paths from the same AS, and any difference higher in the list makes it moot. If you need to prefer one provider over another, MED is the wrong tool — that is what local preference is for.

A note on MED

MED is the most misunderstood attribute. It is designed for one job: telling a neighbouring AS which of several entry points into *your* AS you prefer. Because it is only compared between paths received from the same AS, setting MED toward two different providers does nothing — they are never compared. And because it sits at step 6, any difference in weight, local preference, or AS path length makes MED irrelevant.

Reading the decision in show output

On a Cisco router, show ip bgp marks the selected best path with a > at the start of the line. The columns tell the story of the decision: LocPrf shows local preference (blank means the default 100), Weight shows 0 for learned paths and 32768 for locally originated ones, and Path lists the AS sequence. When a path you expected to win isn't marked, read the columns left to right against the decision order — the first column where the winner beats your candidate is the step that decided. Engineers debugging traffic flows do exactly this: find the prefix, compare the two lines, and identify the deciding attribute before changing any policy.

At a glance: why, where, when, how

  • Why: the internet is thousands of separate networks; something must decide how traffic passes between them.
  • Where: between ISPs, and between any large organisation and its internet providers.
  • When: whenever a network connects to the internet through one or more providers and wants control over the paths.
  • How: routers compare candidate paths attribute by attribute in a fixed order — local preference before AS-path length, MED near the end — as this article walks through.

Advantages and disadvantages

Advantages

  • Total policy control: the operator, not raw topology, decides where traffic goes.
  • Proven at internet scale: it is the protocol the entire internet runs on.
  • Flexible traffic engineering: different prefixes can prefer different providers.

Disadvantages

  • Complex: the attribute list is long, and a small policy mistake can redirect (or blackhole) traffic.
  • Slow to converge compared with OSPF — minutes, not seconds, after big changes.
  • "Shortest" is not guaranteed: the chosen path is the most preferred, not the fastest.

Real-life example

A company buys internet from two providers: a cheap one and a premium one. Normal web traffic is sent over the cheap provider; the video-conferencing traffic that the business depends on is given a higher local preference over the premium provider. Both paths reach the same internet — BGP simply follows the company's policy about which traffic deserves which road.

FAQ

What is the difference between weight and local preference?

Weight is local to one router and never advertised; local preference is advertised to all iBGP neighbours and applies AS-wide. Use weight for a single router's exception, local preference for AS-wide policy.

Why is eBGP preferred over iBGP at step 7?

An eBGP-learned path means the destination is directly reachable through that neighbour — the router is already at the AS boundary. An iBGP path still needs an internal hop.

Does BGP load-balance?

By default, no — one best path is selected and installed. Multipath BGP exists but must be explicitly enabled.

Related: BGP Best Path Lab