In a Nutshell

Routing at the scale of the global internet requires a rigid, multi-variable decision process. This article breaks down the BGP best-path algorithm.

Introduction to BGP Decision Making

Unlike Interior Gateway Protocols (IGPs) like OSPF or EIGRP, which typically use a simple metric like cost or bandwidth, the Border Gateway Protocol (BGP) uses a complex, hierarchical list of attributes to select the "Best Path." BGP is a path-vector protocol designed for policy enforcement, not just shortest-path calculation.

The Selection Algorithm Hierarchy

When a BGP router receives multiple routes to the same prefix, it applies the following tie-breaking rules in order. The first rule that produces a single winner stops the process:

BGP Traffic Engineering Flow

Simulate inbound/outbound path selection metrics

Best Path: Path A
Path A (Primary ISP)
Local Preference100
AS-Path Length2 Hops
Path B (Secondary)
Local Preference100
AS-Path Length3 Hops
Local ASCloud
Traffic Engineering Simulator
Decision Insight:Local Preference tied. AS-Path length of 2 is preferred. Routing policies typically favor the shorter topological distance.

BGP Best-Path Decision Funnel

WINNER: ISP-ALPHA
ISP-Alpha
ISP-Bravo
ISP-Delta
Weight
Alpha
Bravo
Delta
Tie → Next
Local Preference
Alpha
Bravo
Delta
Tie → Next
AS Path
Alpha
Bravo
Delta
Tie → Next
Origin
Alpha
Delta
Tie → Next
MED
Alpha
Delta
Tie → Next
BGP Type
Alpha
Delta
Decision Logic Trace

The router selected ISP-Alpha because it had the ebgp-first BGP Type at the BGP Type filter stage.

Pro-Tips: Use Weight for local router preference (Cisco specific). Use Local Preference to influence outbound traffic for the entire AS. Use AS-Path Prepending (increasing hops) or MED to influence how neighbors send traffic TO you.
  1. Weight (Cisco Proprietary): Highest weight is preferred. Local to the router.
  2. Local Preference: Highest local preference (default 100) is preferred. Shared within the AS.
  3. Locally Originated: Prefer routes originated by this router (network/aggregate commands).
  4. AS-Path Length: Shortest AS-Path is preferred.
  5. Origin Type: Prefer IGP over EGP, and EGP over Incomplete.
  6. Multi-Exit Discriminator (MED): Lowest MED is preferred (usually exchanged between neighboring ASes).
  7. External vs. Internal: Prefer eBGP paths over iBGP paths.
  8. IGP Metric to Next Hop: Prefer the path with the lowest IGP metric to the BGP next hop.

Mathematical Influence: AS-Path Prepending

Network engineers often use "AS-Path Prepending" to discourage inbound traffic from choosing a specific link. By artificially inflating the AS-Path length, the path becomes less attractive to the selection algorithm.

Leffective=Loriginal+NprependingL_{effective} = L_{original} + N_{prepending}

Where NN is the number of times the local AS number is repeated in the path attribute.

Conclusion

Understanding this hierarchy is critical for traffic engineering. By adjusting these attributes, engineers can control how their data leaves the network (Outbound Policy via Local Preference) and how external traffic enters (Inbound Policy via AS-Path Prepending or MED).

Share Article

Technical Standards & References

REF [1]
IETF (2006)
RFC 4271: A Border Gateway Protocol 4 (BGP-4)
VIEW OFFICIAL SOURCE
REF [2]
Cisco Systems (2023)
BGP Path Selection Guide
Mathematical models derived from standard engineering protocols. Not for human safety critical systems without redundant validation.

Related Engineering Resources