6.2 BGP Path Attributes and the Step-by-Step Best Path Selection Algorithm

Key Takeaways

  • BGP path attributes are categorized into four distinct classes: Well-known Mandatory, Well-known Discretionary, Optional Transitive, and Optional Non-transitive.

  • Cisco's BGP best path selection algorithm evaluates attributes in a deterministic sequence, beginning with Cisco-proprietary Weight (local to router), followed by Local Preference (AS-wide), and locally originated routes.

  • Path length and metric tie-breakers prioritize shortest AS_PATH, lowest Origin code (IGP < EGP < Incomplete), lowest MED, eBGP over iBGP, and lowest IGP metric to the BGP next-hop.

  • Inbound traffic engineering influences external AS path selection via AS_PATH prepending and Multi-Exit Discriminator (MED), while outbound traffic engineering is managed locally via Weight and Local Preference.

  • Final BGP deterministic tie-breakers resolve equal candidate paths through oldest eBGP path, lowest BGP Router ID (RID), and lowest neighbor peering IP address.

Last updated: October 2026

BGP Path Attributes and the Step-by-Step Best Path Selection Algorithm

Border Gateway Protocol (BGP) is fundamentally a policy-driven routing engine rather than a pure shortest-path protocol. Unlike Interior Gateway Protocols that compute link costs from physical metrics such as bandwidth or interface delay, BGP equips network administrators with granular administrative control over transit paths across autonomous boundaries. When a BGP speaker learns multiple paths to the exact same prefix with the same subnet mask, it subjects all candidate paths to a rigorous, sequential decision ladder known as the BGP Best Path Selection Algorithm.


BGP Path Attribute Classification Matrix

Every BGP route is bundled with path attributes that describe its origin, forwarding characteristics, and administrative preference. RFC standards classify BGP path attributes into four distinct operational categories:

                         +-----------------------------+
                         |     BGP Path Attributes     |
                         +-----------------------------+
                                 /             \
                                /               \
                   +---------------+         +--------------+
                   |  Well-Known   |         |   Optional   |
                   +---------------+         +--------------+
                       /       \                 /       \
                      /         \               /         \
           +-----------+   +---------------+ +----------+  +--------------+
           | Mandatory |   | Discretionary | |Transitive|  |Non-Transitive|
           +-----------+   +---------------+ +----------+  +--------------+
           | AS_PATH   |   | LOCAL_PREF    | |COMMUNITY |  | MED          |
           | NEXT_HOP  |   | ATOMIC_AGGR   | |AGGREGATOR|  | ORIGINATOR_ID|
           | ORIGIN    |   +---------------+ +----------+  | CLUSTER_LIST |
           +-----------+                                   +--------------+
CategoryDefinition and Behavioral RulesKey Path Attributes
Well-Known MandatoryMust be recognized by all compliant BGP implementations and must be included in every BGP Update advertisement.• AS_PATH: Ordered sequence of ASNs traversed; • NEXT_HOP: Next-hop IP address to forward traffic toward; • ORIGIN: Historical origin of route (IGP i, EGP e, Incomplete ?).
Well-Known DiscretionaryMust be recognized by all compliant BGP implementations, but optional to include in an Update advertisement.• LOCAL_PREF: Egress path preference across an AS (default 100); • ATOMIC_AGGREGATE: Informs downstream peers that route summarization suppressed more specific prefix details.
Optional TransitiveImplementations may or may not support it. If unrecognized, the router must accept and preserve the attribute, propagating it to downstream peers.• COMMUNITIES: 32-bit tagging values for route policy; • AGGREGATOR: Identifies BGP Router ID and ASN of aggregating router.
Optional Non-TransitiveImplementations may or may not support it. If unrecognized, the router silently drops the attribute and does not propagate it to other peers.• MULTI_EXIT_DISC (MED): Metric used to suggest ingress preference to a neighboring AS; • ORIGINATOR_ID: Router ID of route creator (Route Reflector loop prevention); • CLUSTER_LIST: List of cluster IDs traversed within RR topologies.

Cisco Weight Attribute: The Cisco-proprietary Weight attribute is not exchanged between BGP neighbors and is never carried in BGP Update messages. It is purely local to the router on which it is configured.


The Step-by-Step BGP Best Path Selection Algorithm

When a Cisco router receives multiple valid paths to an identical IP prefix and mask, it executes the following 12-step decision ladder in strict sequential order. Evaluation stops immediately as soon as a single tie-breaker selects a winning path:

                     [Evaluate Candidate Paths]
                                  |
                                  v
                   1. Highest Weight (Cisco Local)
                                  |
                                  v
                 2. Highest Local Preference (AS-Wide)
                                  |
                                  v
                 3. Prefer Locally Originated Routes
                                  |
                                  v
                      4. Shortest AS_PATH Length
                                  |
                                  v
                 5. Lowest Origin Code (IGP < EGP < ?)
                                  |
                                  v
                 6. Lowest MED (Metric from Neighbor AS)
                                  |
                                  v
                   7. Prefer eBGP over iBGP Paths
                                  |
                                  v
              8. Lowest IGP Metric to the BGP Next_Hop
                                  |
                                  v
             9. Multipath (Install ECMP if enabled)
                                  |
                                  v
               10. Oldest eBGP Path (Route Stability)
                                  |
                                  v
                   11. Lowest BGP Router ID (RID)
                                  |
                                  v
             12. Lowest Neighbor Peering IP Address

Step 1: Highest Weight (Cisco Proprietary)

  • Scope: Purely local to the router. It is never advertised to any BGP peer (eBGP or iBGP).
  • Range: 0 to 65,535. Defaults to 32,768 for locally originated routes (via network or redistribute) and 0 for all routes learned from neighbors.
  • Tie-Breaker: The path with the highest Weight wins.

Step 2: Highest Local Preference (LOCAL_PREF)

  • Scope: Propagated throughout the entire local Autonomous System across all iBGP peers. It is never transmitted across eBGP peering boundaries.
  • Range: 0 to 4,294,967,295. Default value is 100.
  • Tie-Breaker: The path with the highest Local Preference wins. This is the primary mechanism for controlling outbound Internet traffic for an enterprise.

Step 3: Locally Originated Routes

  • Prefers paths that were originated locally on this router over paths learned from other routers.
  • Cisco's documented order: local paths sourced by network or redistribute are preferred over local aggregates created with aggregate-address, and any locally originated path beats a path learned from a neighbor.

Step 4: Shortest AS_PATH Length

  • Counts the number of Autonomous System numbers in the AS_PATH attribute list.
  • Tie-Breaker: The path with the fewest AS numbers wins.
  • Rules: An AS_SET counts as 1 AS number regardless of how many ASNs are in the set. AS confederation sequences (AS_CONFED_SEQUENCE) do not count toward AS_PATH length.

Step 5: Lowest Origin Code

  • Evaluates how the prefix was initially introduced into BGP:
    1. IGP (i): Originated via BGP network command (most preferred).
    2. EGP (e): Originated via legacy Exterior Gateway Protocol (historic; intermediate preference).
    3. Incomplete (?): Originated via route redistribution into BGP (least preferred).
  • Hierarchy: IGP (i) < EGP (e) < Incomplete (?).

Step 6: Lowest Multi-Exit Discriminator (MED)

  • Scope: Transmitted to neighboring external ASes to influence their ingress choice. By default, MED is only compared between routes advertised by the same neighboring Autonomous System.
  • Tie-Breaker: The path with the lowest MED (metric) wins. A missing MED attribute is treated as metric 0 by default in Cisco IOS.
  • Configuration Override: The bgp always-compare-med router configuration command forces the router to compare MED across paths originating from different autonomous systems.

Step 7: Prefer eBGP over iBGP Paths

  • Paths learned from external eBGP peers are preferred over paths learned from internal iBGP peers.
  • Confederation eBGP paths (eBGP confederation) are treated as having an intermediate preference between pure eBGP and iBGP.

Step 8: Lowest IGP Metric to the BGP Next_Hop

  • Evaluates the internal IGP routing table (OSPF, EIGRP, IS-IS) to find the metric cost to reach the BGP NEXT_HOP IP address.
  • Tie-Breaker: The path with the lowest IGP metric to the exit next-hop wins. This implements "hot potato routing"—shedding transit packets out of the local autonomous system as quickly as possible.

Step 9: Multipath (Equal-Cost Multi-Path)

  • If the router is configured with maximum-paths <n> under router bgp, and multiple candidate paths are identical from Step 1 through Step 8, BGP installs multiple paths into the routing table for parallel ECMP forwarding.

Step 10: Oldest eBGP Path (Stability)

  • For eBGP paths, the router prefers the path that has been known for the longest duration (the oldest route). This prevents route flapping when a temporary link toggle occurs.
  • Note: This step is bypassed if bgp bestpath compare-routerid is enabled.

Step 11: Lowest BGP Router ID (RID)

  • Compares the 32-bit BGP Router IDs of the advertising neighbors. The path with the lowest Router ID wins.
  • Route Reflector Exception: If the route was received through a BGP Route Reflector, the ORIGINATOR_ID attribute is compared instead of the advertising neighbor's Router ID.

Step 12: Lowest Neighbor Peering IP Address

  • The final deterministic tie-breaker: prefers the path learned from the neighbor with the lowest IP address.
  • Route Reflector note: when paths arrive through route reflectors, Cisco compares CLUSTER_LIST length (shorter wins) just before this step.

Master BGP Best Path Tie-Breaker Table

StepEvaluation CriterionScope / PropagationDefault ValuePreference Direction
1WeightRouter-local only (never advertised)0 (learned), 32768 (local)Highest
2Local PreferenceAS-wide (flooded across iBGP)100Highest
3Locally OriginatedLocal routerN/ALocal > Remote
4AS_PATH LengthGlobal (propagated everywhere)Dynamic listShortest
5Origin CodeGlobal (propagated everywhere)i, e, or ?Lowest (i < e < ?)
6MED (Metric)Inter-AS (adjacent neighbor AS)0Lowest
7Peer TypeInter-AS vs. Intra-ASeBGP vs. iBGPeBGP > iBGP
8IGP Cost to Next_HopLocal AS (interior routing table)IGP metric (OSPF/EIGRP)Lowest
9MultipathLocal router forwarding planeDisabled (default 1)ECMP installation
10Route AgeLocal router (eBGP paths only)Uptime timestampOldest (Most Stable)
11BGP Router IDNeighbor BGP process ID32-bit dotted-decimalLowest
12Neighbor Peering IPPeering TCP endpointIPv4/IPv6 addressLowest

Traffic Engineering: Inbound vs. Outbound Control

Enterprise networks dual-homed to multiple Service Providers must manipulate BGP attributes to steer traffic deterministically:

1. Outbound Traffic Engineering (Influencing Local Egress)

To control how traffic inside your enterprise exits toward external destinations, configure Local Preference or Weight on routes received from upstream ISPs:

  • Local Preference (Recommended): Applied to incoming eBGP route updates. Because Local Preference is carried across all iBGP routers, setting LOCAL_PREF 200 on ISP-1 and LOCAL_PREF 100 on ISP-2 ensures that all internal routers egress through ISP-1.
  • Weight: Applied to incoming routes on a single border router. Effective only if a single router terminates both ISP connections.

2. Inbound Traffic Engineering (Influencing External Ingress)

To control how external networks send traffic into your enterprise, configure AS_PATH Prepending or MED on routes advertised out to ISPs:

  • AS_PATH Prepending: Artificially lengthens the AS_PATH advertised to a secondary ISP by repeating your own AS number multiple times (e.g., set as-path prepend 65100 65100 65100). Upstream BGP speakers observe a longer path and prefer the primary ISP.
  • Multi-Exit Discriminator (MED): Advertising a lower MED on the primary link and higher MED on the backup link signals the adjacent ISP to prefer the primary link. Note that MED only influences the immediate neighbor AS and may be overridden by the ISP's local preference policy.

Cisco IOS Route Manipulation Implementation

The following configuration demonstrates outbound egress steering via Local Preference and inbound ingress steering via AS_PATH prepending on Router R1 (AS 65100):

! Define prefix-list matching local public enterprise subnet
ip prefix-list PL_LOCAL_PREFIX permit 192.0.2.0/24
!
! Outbound policy: Prefer ISP-1 for Internet egress by setting Local_Pref 200
route-map RM_FROM_ISP1_IN permit 10
 set local-preference 200
!
route-map RM_FROM_ISP2_IN permit 10
 set local-preference 100
!
! Inbound policy: Deprioritize ISP-2 for incoming traffic via AS-Path prepending
route-map RM_TO_ISP1_OUT permit 10
 match ip address prefix-list PL_LOCAL_PREFIX
!
route-map RM_TO_ISP2_OUT permit 10
 match ip address prefix-list PL_LOCAL_PREFIX
 set as-path prepend 65100 65100 65100
!
router bgp 65100
 neighbor 198.51.100.2 remote-as 65200
 neighbor 198.51.100.2 description Primary ISP-1
 neighbor 198.51.100.2 route-map RM_FROM_ISP1_IN in
 neighbor 198.51.100.2 route-map RM_TO_ISP1_OUT out
!
 neighbor 203.0.113.2 remote-as 65300
 neighbor 203.0.113.2 description Backup ISP-2
 neighbor 203.0.113.2 route-map RM_FROM_ISP2_IN in
 neighbor 203.0.113.2 route-map RM_TO_ISP2_OUT out

BGP Table Analysis and Verification

Interpreting the show ip bgp output is essential for identifying which path won the best-path algorithm:

R1# show ip bgp 203.0.113.0/24
BGP routing table entry for 203.0.113.0/24, version 14
Paths: (2 available, best #1, table default)
  Advertised to update-groups:
     1
  Refresh Epoch 1
  65200
    198.51.100.2 from 198.51.100.2 (198.51.100.2)
      Origin IGP, metric 0, localpref 200, weight 0, valid, external, best
      rx path info: flag 0x41, orig-as 65200, localpref 200, metric 0
  Refresh Epoch 1
  65300
    203.0.113.2 from 203.0.113.2 (203.0.113.2)
      Origin IGP, metric 0, localpref 100, weight 0, valid, external
      rx path info: flag 0x01, orig-as 65300, localpref 100, metric 0

In standard table summaries (show ip bgp), look for the status indicator codes:

  • *: The route is valid (the next-hop is resolvable in the routing table).
  • >: The route is chosen as the best path and is installed into the IP Routing Information Base (RIB).
  • i: The route was learned via an internal iBGP peer.
Test Your Knowledge

An enterprise network is multihomed to two Internet Service Providers: ISP-A (via GigabitEthernet0/0/1) and ISP-B (via GigabitEthernet0/0/2). The enterprise wants to ensure that all outbound Internet traffic generated by internal hosts prefers ISP-A across the entire autonomous system. Which BGP route manipulation method should the architect apply?

A

Apply an outbound route-map to ISP-B setting the MED metric to 500.

B

Apply an outbound route-map to ISP-A prepending the enterprise AS number three times.

C

Apply an inbound route-map on the peering session with ISP-A that sets the Local Preference to 200.

D

Configure the Weight attribute to 65535 on the peering session with ISP-B.

Test Your Knowledge

Which of the following correctly categorizes the Multi-Exit Discriminator (MED) attribute and describes its propagation across autonomous systems?

A

Optional Non-transitive; it influences a neighbor AS's inbound choice and is not passed beyond that AS.

B

Well-known Discretionary; it is flooded across all autonomous systems to determine the global shortest path.

C

Optional Transitive; intermediate routers pass the attribute unaltered to all downstream external peers across the Internet.

D

Well-known Mandatory; every BGP Update must include a MED value to prevent inter-AS forwarding loops.

Test Your Knowledge

A Cisco edge router receives two valid BGP paths to destination prefix 10.50.0.0/16 with identical characteristics:

  • Path 1: Learned via eBGP, Weight 0, Local_Pref 100, AS_PATH 65200 65300 (length 2), Origin IGP, MED 50, IGP metric to Next_Hop 10.
  • Path 2: Learned via iBGP, Weight 0, Local_Pref 100, AS_PATH 65400 65500 (length 2), Origin IGP, MED 50, IGP metric to Next_Hop 5. Which path does the BGP best path selection algorithm select as the primary route, and which tie-breaker decides the outcome?
A

Path 2 because its IGP metric to the BGP Next_Hop is lower (5 vs 10), and IGP cost is checked first

B

Path 2 because iBGP routes are trusted more than eBGP routes inside the local autonomous system.

C

Path 1 because the lowest AS number in the AS_PATH is preferred.

D

Path 1 because eBGP is preferred over iBGP before the IGP metric to the Next_Hop is compared.

Sections you finish are checked off in the contents.