BGP Path Selection Algorithm Explained Step by Step – Complete CCNP Guide

BGP Path Selection Algorithm Explained Step by Step – Complete CCNP Guide
Networking ATN Campus November 13, 2026 26 views

BGP Path Selection Algorithm Explained Step by Step – Complete CCNP Guide

BGP (Border Gateway Protocol) is responsible for exchanging routing information between autonomous systems. However, a router may receive multiple possible routes to reach the same destination network.

How does BGP decide which route should be installed as the best path?

BGP uses a path-selection process that examines several attributes, including Weight, Local Preference, AS_PATH, Origin, MED, and other routing information.

In this CCNP tutorial, you will learn how BGP selects the best path, understand the most important BGP attributes, and configure practical examples using Cisco IOS commands.

1. What Is BGP Path Selection?

BGP Path Selection is the process of choosing the preferred route when multiple BGP paths exist for the same destination prefix.

A BGP router may learn the same prefix from multiple neighbors. It evaluates the available paths and selects a best path based on its decision process and configured routing policies.

For example:

                 ISP 1
                   |
                   |
                 Router
                   |
                   |
                 ISP 2

       Two possible routes to the same prefix

The router evaluates both paths and selects the preferred route according to BGP's path-selection rules.

2. Important BGP Path Attributes

BGP uses path attributes to describe and compare routes. Some of the most important attributes are:

AttributePurpose
WeightLocal Cisco-specific preference for a path on one router.
Local PreferenceIndicates the preferred exit path within an autonomous system.
Locally OriginatedRoutes originated locally are preferred over routes learned from peers at this stage of Cisco's selection process.
AS_PATHLists the autonomous systems through which a route has travelled.
OriginIndicates how a route was introduced into BGP.
MEDSuggests a preferred entry point into an autonomous system.
eBGP vs iBGPWhen earlier criteria tie, an eBGP-learned path is preferred over an iBGP-learned path.
IGP Metric to Next HopCompares the internal cost to reach the BGP next-hop address.

3. BGP Path Selection Order

Cisco's commonly taught BGP best-path decision sequence includes the following major criteria. Some tie-breakers and implementation details depend on platform, software version, and configuration.

  1. Prefer the highest Weight.
  2. Prefer the highest Local Preference.
  3. Prefer a locally originated route.
  4. Prefer the shortest AS_PATH.
  5. Prefer the lowest Origin type: IGP, then EGP, then Incomplete.
  6. Prefer the lowest MED, when MED comparison applies.
  7. Prefer an eBGP path over an iBGP path.
  8. Prefer the path with the lowest IGP metric to the BGP next hop.
  9. Apply additional tie-breakers when paths are still equal.

This is a useful learning sequence for Cisco CCNP studies, but it is not a complete universal ordering for every BGP implementation or configuration. Cisco also uses additional tie-breakers, and options such as multipath can allow multiple paths to be installed.

4. Step 1 – Weight

Weight is a Cisco-specific BGP attribute. It is locally significant and is not advertised to other BGP routers.

The router prefers the path with the highest Weight.

Example:

PathWeight
Path A300
Path B200

Path A is preferred because it has the higher Weight.

Example configuration:

router bgp 65001
 neighbor 10.0.12.2 weight 300

This assigns a Weight of 300 to routes learned from that neighbor on this router.

5. Step 2 – Local Preference

Local Preference is used within an autonomous system to influence which exit path routers prefer when sending traffic to external destinations.

A higher Local Preference is preferred.

Example:

PathLocal Preference
ISP 1200
ISP 2100

The route through ISP 1 is preferred because it has a higher Local Preference.

Example configuration:

route-map PREFER-ISP1 permit 10
 set local-preference 200

router bgp 65001
 neighbor 10.0.12.2 route-map PREFER-ISP1 in

This example applies Local Preference to routes received from the specified neighbor. The route-map is applied inbound to the BGP session.

6. Step 3 – Locally Originated Routes

When earlier attributes are equal, Cisco's BGP selection process prefers routes that the local router originated.

A router can originate routes using methods such as:

  • A BGP network statement.
  • Redistribution into BGP.
  • Other supported local route-origination mechanisms.

For a network statement to advertise a prefix, the exact prefix and mask must exist in the local routing table.

7. Step 4 – AS_PATH

AS_PATH is a BGP path attribute that identifies the sequence of autonomous systems a route has traversed.

In the usual Cisco best-path comparison, a shorter AS_PATH is preferred when the earlier criteria tie.

Example:

PathAS_PATHLength
Path A65010 650202
Path B65030 65040 650503

Path A is preferred because it has the shorter AS_PATH.

AS_PATH also helps prevent routing loops in eBGP. A router normally rejects an eBGP route if its own AS number is already present in the AS_PATH.

8. Step 5 – Origin Attribute

The Origin attribute indicates how a route was introduced into BGP.

There are three main Origin values:

OriginCodeMeaning
IGPiIntroduced using a BGP network statement or similar IGP-origin indication.
EGPeIntroduced through the historical Exterior Gateway Protocol.
Incomplete?Origin is incomplete, commonly associated with redistribution.

When comparing otherwise equal paths, the preferred order is IGP, then EGP, then Incomplete.

9. Step 6 – MED (Multi-Exit Discriminator)

MED is used to suggest a preferred entry point into an autonomous system when multiple links connect two autonomous systems.

A lower MED is preferred when MED comparison applies.

Example:

PathMED
ISP Connection 150
ISP Connection 2150

If the paths are eligible for MED comparison and earlier attributes tie, the path with MED 50 is preferred.

Important: By default, Cisco commonly compares MED values between paths learned from the same neighboring AS. Configuration can change MED comparison behavior.

10. Step 7 – eBGP vs iBGP

If the earlier path-selection criteria are equal, BGP generally prefers a route learned from an eBGP peer over one learned from an iBGP peer.

This preference helps select an external path when otherwise comparable routes are available.

11. Step 8 – IGP Metric to the BGP Next Hop

BGP also considers the internal routing cost to reach the next-hop address.

When the earlier criteria tie, the path with the lower IGP metric to its next hop is generally preferred.

This is important in networks with multiple internal paths to external BGP next hops.

12. Practical BGP Path Selection Lab

Let's configure a router with two external BGP connections and compare the routes it receives.

              ISP 1
             AS 65010
                |
                |
              R1
                |
                |
              R2
                |
                |
              ISP 2
             AS 65020

          Enterprise AS 65001

For this lab, R1 is the enterprise edge router and has two external BGP peers. Use a separate point-to-point link to each ISP.

Example addressing plan:

ConnectionEnterprise SideISP Side
R1–ISP110.0.12.1/3010.0.12.2/30
R1–ISP210.0.13.1/3010.0.13.2/30

R1 – Enterprise BGP Configuration

router bgp 65001
 neighbor 10.0.12.2 remote-as 65010
 neighbor 10.0.13.2 remote-as 65020

ISP1 Configuration

router bgp 65010
 neighbor 10.0.12.1 remote-as 65001
 network 203.0.113.0 mask 255.255.255.0

ISP2 Configuration

router bgp 65020
 neighbor 10.0.13.1 remote-as 65001
 network 203.0.113.0 mask 255.255.255.0

For the demonstration, ensure the prefix 203.0.113.0/24 exists in the routing table of both ISP routers before using the network statements.

The two ISPs advertise the same prefix to R1. R1 can now inspect the competing paths.

13. Configure Weight to Prefer ISP1

To prefer routes received from ISP1 using Cisco Weight:

router bgp 65001
 neighbor 10.0.12.2 weight 300

Check the BGP routing table:

show ip bgp 203.0.113.0

The route received from ISP1 should have the higher Weight and be preferred if the route is otherwise eligible.

14. Configure Local Preference to Prefer ISP2

Now use Local Preference to prefer ISP2. Local Preference is propagated to other iBGP peers within the AS, unlike Weight.

route-map PREFER-ISP2 permit 10
 set local-preference 250

router bgp 65001
 neighbor 10.0.13.2 route-map PREFER-ISP2 in

The higher Local Preference from ISP2 should take precedence over the lower Local Preference from ISP1 when the paths are compared at the relevant selection stage.

For a clean demonstration of Local Preference, remove or equalize any Weight settings that would otherwise decide the best path first.

15. BGP Verification Commands

Check BGP Summary

show ip bgp summary

Check the BGP Routing Table

show ip bgp

Inspect a Specific Prefix

show ip bgp 203.0.113.0

Check the Selected Route

show ip route 203.0.113.0

Check Received Routes

show ip bgp neighbors 10.0.12.2 received-routes

The received-routes command may require inbound soft reconfiguration to have been enabled, depending on the platform and configuration.

16. Common BGP Path Selection Problems

ProblemPossible CauseSolution
Unexpected ISP path selectedHigher Weight or Local PreferenceInspect BGP path attributes
Expected route missingPrefix not advertised or filteredCheck network statements and route policies
Next hop is unreachableMissing IGP or static routeProvide next-hop reachability
Unexpected AS_PATH preferenceAS_PATH length or policy differencesInspect the complete BGP path
MED has no expected effectPaths are not eligible for MED comparisonReview neighboring AS and MED comparison settings

17. Frequently Asked Questions

Q1. What is BGP Path Selection?

BGP Path Selection is the process used to choose the preferred route when multiple paths to the same prefix are available.

Q2. Which BGP attribute is preferred first in Cisco's commonly taught best-path sequence?

Weight is compared first, with the highest value preferred.

Q3. What is Local Preference?

Local Preference is a BGP attribute used within an autonomous system to influence the preferred exit path. A higher value is preferred.

Q4. What is AS_PATH?

AS_PATH records the autonomous systems a route has travelled through. A shorter path is generally preferred when earlier criteria tie.

Q5. What is MED?

MED is an attribute used to suggest a preferred entry point into an autonomous system. A lower value is preferred when MED comparison applies.

18. Practical CCNP Lab Challenge

  1. Build an enterprise router connected to two ISP routers.
  2. Configure two eBGP neighbor relationships.
  3. Advertise the same prefix from both ISPs.
  4. Inspect both paths using show ip bgp.
  5. Configure Weight to prefer ISP1.
  6. Remove the Weight preference and configure Local Preference to prefer ISP2.
  7. Compare routes with different AS_PATH lengths.
  8. Experiment with MED values.
  9. Verify the selected route in the IP routing table.

Conclusion

Understanding the BGP Path Selection Algorithm is essential for designing reliable multi-ISP and enterprise routing networks. Attributes such as Weight, Local Preference, AS_PATH, Origin, and MED allow network engineers to control how traffic enters and leaves an autonomous system.

Practice each attribute in a lab environment and inspect the BGP routing table after every configuration change. This will help you understand how BGP makes routing decisions in real-world networks.

???? Advance Your Networking Career with ATN Campus

Want to master advanced routing and switching? Visit ATN Campus to explore CCNA, CCNP Enterprise, BGP, OSPF, EIGRP, network security, and hands-on Cisco networking labs.

???? Learn Networking. ???? Master Advanced Routing & Switching. ???? Practice with Real Labs. ???? Prepare for CCNP Certifications. ???? Build Your IT Career with ATN Campus.
Document ATN CAMPUS