Free tech learning for everyone, from basics to pro

Routing & SwitchingNetworking SecurityAdvanced

BGP path attributes and best path selection: weight, local preference, AS path, MED and more

In short: BGP chooses one best path per prefix by comparing attributes in a fixed order. Weight and local preference let you choose your exit; AS_PATH prepending and MED let you suggest how others should enter your network. Learning the order, and which attributes travel where, is the key to BGP traffic engineering.

Attribute types

Each BGP route carries path attributes. RFC 4271 groups them into four types:

  • Well-known mandatory: in every update. AS_PATH, NEXT_HOP and ORIGIN.
  • Well-known discretionary: understood by everyone but optional to send. LOCAL_PREF and ATOMIC_AGGREGATE.
  • Optional transitive: passed on even by routers that do not understand them. COMMUNITIES and AGGREGATOR.
  • Optional non-transitive: not passed on. MULTI_EXIT_DISC (MED).

Cisco adds weight, a value that never leaves the router.

The selection order

Cisco BGP best path order (main steps)1. Highest weightCisco only, local to the router2. Highest local preferenceshared across the whole AS3. Locally originated, then AIGPown routes win4. Shortest AS_PATH, then lowest originIGP before incomplete5. Lowest MED, then eBGP over iBGPMED from the same neighbour AS6. Lowest IGP metric, then tie-breakersoldest path, router ID
Figure 1. BGP compares paths attribute by attribute and stops at the first difference. Weight and local preference control your outbound traffic; AS_PATH prepending and MED influence how others reach you.

Before comparing anything, BGP ignores paths whose next hop is unreachable. Then, on Cisco IOS:

  1. Highest weight. Default 32768 for routes the router originates, 0 for learned routes.
  2. Highest local preference. Default 100, shared with all iBGP peers.
  3. Locally originated (network, aggregate or redistribute) over learned.
  4. Lowest AIGP (accumulated IGP metric), if used. It suits large networks spanning several ASes under one operator.
  5. Shortest AS_PATH.
  6. Lowest origin: IGP before EGP before incomplete.
  7. Lowest MED, compared only between paths from the same neighbouring AS unless configured otherwise.
  8. eBGP over iBGP.
  9. Lowest IGP metric to the next hop.
  10. Tie-breakers: oldest eBGP path, lowest router ID, shortest cluster list, lowest neighbour address.

Controlling traffic leaving your AS

Weight affects only one router, so it is useful when a single router has two providers. Local preference is the usual tool for the whole AS: set it on routes learned from your preferred provider and every internal router follows.

route-map FROM-ISP-A permit 10
 set local-preference 200
router bgp 64500
 neighbor 198.51.100.1 route-map FROM-ISP-A in

Influencing traffic entering your AS

You cannot directly control other networks' decisions, but you can make some paths look less attractive:

  • AS_PATH prepending: add your own ASN several times to routes sent to the backup provider, so the path looks longer.
  • MED: tell a neighbouring AS that has two links to you which link to prefer. Lower is better, and it only works with that one neighbour.
  • Communities defined by your provider, and advertising more specific prefixes on the preferred link, are also common.
route-map TO-ISP-B permit 10
 set as-path prepend 64500 64500 64500
router bgp 64500
 neighbor 192.0.2.1 route-map TO-ISP-B out

Prepending more than three or four times rarely helps further, because many networks set local preference on customer routes, and that is checked before AS_PATH length.

Multipath

By default BGP installs one best path. maximum-paths 2 (eBGP) or maximum-paths ibgp 2 lets the router load-share across several paths, but only if they tie on weight, local preference, AS_PATH length, origin, MED and IGP metric. The best path is still the only one advertised to peers.

Real-world example: a hospital group had a fast fibre service from one provider and a cheaper backup from another. All outbound traffic used the backup, because its routes happened to have shorter AS paths. The engineer set local preference 200 on routes learned from the primary provider, which moved outbound traffic straight away. Inbound traffic still arrived via the backup, so he prepended the hospital's ASN three times on announcements to the backup provider. Within minutes most inbound traffic shifted to the primary link, leaving the backup idle until needed.

Practice

Which attribute would you set to make every router in your AS prefer one provider for outbound traffic?
Local preference (higher wins), applied inbound on routes from that provider.
Is a lower or higher MED preferred?
Lower. MED is also only compared between paths from the same neighbouring AS by default.
Why might AS_PATH prepending fail to move inbound traffic?
The other network may set local preference on its routes, which is compared before AS_PATH length, so a longer path still wins.

Key takeaways

  • BGP compares attributes in a fixed order and stops at the first difference.
  • Weight is local to one Cisco router; local preference applies to the whole AS.
  • Shorter AS_PATH wins; prepending makes a path look longer to others.
  • Lower MED is preferred, between paths from the same neighbouring AS.
  • Multipath needs paths that tie on the main attributes.
Tracks your learning on this device only. See your progress on the learning paths.

About the author

Mohamed Fayas

Founder of FM TecHub. CCNA certified, with a BTEC HND in Network Engineering, and BEng (Hons) in Computer Networking and Cloud Security. He writes practical, plain-English guides on networking, security and cloud.

More about the author

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Stay up to date by email

New notes, tools and security news from FM TecHub, explained simply. Free.

We only use your email to send these updates. See our privacy policy.