Hello! Welcome to the next lesson in our Advanced BGP Routing module.
In our previous session, you learned the essential skills to configure and verify eBGP and iBGP peering for both IPv4 and IPv6. You now know how to get BGP routers talking to each other. But what happens when a router learns multiple ways to reach the same destination network? This lesson tackles that exact question.
Today, we will focus on the learning outcome: Analyze the BGP path selection algorithm and the influence of key attributes (e.g., weight, local preference, AS path).
Unlike IGPs that use a simple metric like cost or hop count, BGP uses a sophisticated, multi-step algorithm based on a rich set of path attributes. As a solutions engineer, mastering this algorithm is crucial for designing and troubleshooting enterprise networks that are connected to multiple service providers or have complex internal routing policies. It's the key to controlling how traffic enters and leaves your network.
1. The BGP Best Path Selection Algorithm
When a BGP router has multiple paths to the same prefix in its BGP table (or BGP Loc-RIB), it must choose only one of them as the "best" path. This best path is what gets installed in the main IP routing table and advertised to other BGP peers.
The decision process is not a calculation; it's a sequential check against a list of rules. The router evaluates the first rule for all available paths. If one path is clearly better based on that rule, it is chosen, and the process stops. If there's a tie, the router moves to the second rule, and so on, until a single best path is found.
This flowchart provides a great visual overview of the key steps in this process.

2. Understanding the Key Path Attributes
To help remember the order of the most common path attributes, network engineers often use the mnemonic: "We Love Oranges As Oranges Mean Pure Refreshment."
Let's dive into what each of these attributes means and how they influence the path selection decision. The following video provides an excellent walkthrough of these attributes and, crucially, shows you where to find them in the output of the show ip bgp command.
BGP - Complete ENCOR (350-401) Exam Coverage
Watch this video from Kevin Wallace Training to get a clear explanation of the main BGP path attributes. It follows the popular mnemonic and connects the theory directly to the CLI output you will see in the real world.
Watch the video from 06:53 to 19:17. The first part (06:53 - 14:03) explains the mnemonic and the attributes conceptually. The second part (14:03 - 19:17) walks through a show ip bgp output, pointing out exactly where to find each attribute. This is key for analysis.
Let's summarize and consolidate the key attributes discussed in the video.
The Decisive Attributes
-
Weight (W):
- Influence: Highest weight is preferred.
- Scope: Cisco-proprietary attribute that is local to the router. It is not advertised to any other BGP peer.
- Use Case: To influence path selection on a single router. A simple way to tell one router, "I want you to prefer this path above all others." By default, routes learned from peers have a weight of 0, while locally originated routes have a weight of 32,768.
-
Local Preference (L):
- Influence: Highest local preference is preferred.
- Scope: Sent to all iBGP peers within the same Autonomous System (AS). It is not sent to eBGP peers.
- Use Case: The standard way to influence the outbound path for an entire AS. All routers in your AS can be told which exit point to prefer to reach an external network. The default value is 100.
-
Locally Originated (O):
- Influence: A path that the router sources itself is preferred over a path learned from any peer.
- Scope: Local to the router.
- Use Case: A router will always trust a route it injected into BGP (e.g., using a
networkcommand) more than a route it learned from someone else. You can identify these routes in theshow ip bgpoutput because their next-hop is0.0.0.0.
-
AS_PATH Length (A):
- Influence: Shortest AS_PATH is preferred.
- Scope: This attribute is fundamental to BGP and is sent to all peers, both iBGP and eBGP.
- Use Case: This is BGP's primary loop-prevention mechanism and its default metric. It essentially functions as a "hop count," where each hop is an entire Autonomous System.
-
Origin Code (O):
- Influence: Lowest code is preferred. The order is: I (IGP) > E (EGP) > ? (Incomplete).
- Scope: Sent to all peers.
- Use Case: Indicates how a route was first injected into BGP.
imeans the route was injected using anetworkcommand somewhere.?means the route was injected via redistribution from another routing protocol (like OSPF or a static route).eis for the obsolete EGP protocol and is almost never seen.
-
Multi-Exit Discriminator (MED) (M):
- Influence: Lowest MED value (metric) is preferred.
- Scope: An optional attribute typically used between two adjacent ASes. It's sent from one AS to another to influence how that other AS sends traffic inbound to the first.
- Complexity: By default, MED is only compared between paths learned from the same neighboring AS. The
bgp always-compare-medcommand can override this, but it must be used carefully.
-
Paths (P):
- Influence: eBGP paths are preferred over iBGP paths.
- Scope: This is an internal decision on the router.
- Use Case: A path learned from an external neighbor is considered more authoritative than a path learned from an internal neighbor.
The Tie-Breakers
If all the above attributes are equal for multiple paths, BGP moves to a series of tie-breakers. The most significant are:
- Lowest IGP metric to the BGP next hop: Prefer the path whose next-hop is closest according to the internal IGP.
- Oldest path (for eBGP): To promote stability, BGP will prefer the path it has known about the longest.
- Lowest Router ID: The path advertised by the BGP peer with the lowest Router ID wins.
3. The Authoritative Reference
For a comprehensive and official list of the BGP path selection steps, the Cisco documentation is the ultimate source. It includes more steps and nuances than the mnemonic covers.
Select BGP Best Path Algorithm
This official Cisco support document provides the complete, ordered list of the BGP best path algorithm. It's a valuable reference for a deep and precise understanding.
Read the section titled 'How the Best Path Algorithm Works'. You don't need to memorize every single step, but focus on the order of the main attributes we've discussed (Weight, LOCAL_PREF, AS_PATH, Origin, MED) and notice where they fit in the full process.
Test your understanding!
A router has two paths to the prefix 198.51.100.0/24. Analyze the show ip bgp output below and determine which path will be selected as the best path. Explain your reasoning step-by-step using the BGP path selection algorithm.
R1# show ip bgp 198.51.100.0
BGP routing table entry for 198.51.100.0/24, version 10
Paths: (2 available, best #2, table default)
Advertised to update-groups:
1
Refresh Epoch 1
65100 65200
10.1.2.2 from 10.1.2.2 (2.2.2.2)
Origin IGP, metric 0, localpref 100, valid, external
Refresh Epoch 1
65300
10.1.3.3 from 10.1.3.3 (3.3.3.3)
Origin IGP, metric 0, localpref 150, valid, external, best
Show answer
The best path will be the one learned from neighbor 10.1.3.3. Here is the step-by-step analysis:
- Weight: The output doesn't show a configured weight for either path, so they both have the default weight of 0 for learned routes. This is a tie.
- Local Preference: The path from
10.1.2.2has a local preference of 100. The path from10.1.3.3has a local preference of 150. - Decision: Since BGP prefers the highest local preference, the path via
10.1.3.3is selected as the best path. The algorithm stops here.
The AS_PATH length is shorter for the second path (1 hop vs 2 hops), but the algorithm never gets to that step because Local Preference is evaluated first and is decisive.
4. BGP Attribute Categories
For a deeper theoretical understanding, it's helpful to know that BGP attributes are classified into four categories. This classification determines how an attribute is handled and whether it must be understood by all BGP speakers.

- Well-known Mandatory: Must be included in every BGP update and understood by all BGP routers (e.g., AS_PATH, Origin, Next Hop).
- Well-known Discretionary: Must be understood by all BGP routers, but doesn't have to be in every update (e.g., Local Preference).
- Optional Transitive: Not all routers need to understand it, but if they don't, they should pass it on to the next peer (e.g., Community).
- Optional Nontransitive: Not all routers need to understand it, and if they don't, they can discard it (e.g., MED).
Weight is a special case as it is Cisco-proprietary and is not advertised at all, so it doesn't fit neatly into this standard classification.
Conclusion
In this lesson, you analyzed the critical BGP best path selection algorithm. You now understand that BGP uses a strict, sequential process to select its best path from multiple options, and you can identify the key attributes that influence this decision.
Key Takeaways:
- BGP uses a strict, ordered algorithm to choose the best path; it is not a formula-based metric.
- The most common and influential attributes can be remembered with the mnemonic "We Love Oranges As Oranges Mean Pure Refreshment".
- Weight influences a single router's outbound path choice (local significance).
- Local Preference is the standard tool to influence an entire AS's outbound path.
- AS_PATH length is BGP's default metric, preferring the path through the fewest autonomous systems.
- MED is used to influence how a neighboring AS sends traffic into your AS.
- You can analyze BGP path selection by examining the attributes in the
show ip bgpcommand output.
Preview of the Next Lesson:
Now that you can analyze how BGP chooses a path, the next logical step is to learn how to actively control it. In our next lesson, we will focus on configuring BGP path attribute manipulation. You'll learn how to use tools like route maps to set attributes like local preference and perform AS-path prepending to engineer traffic flows according to your network policies.