The Hop Count and Loop Guard
The AS-Path attribute is the ordered list of every Autonomous System a route advertisement has passed through to reach you. It serves two purposes simultaneously: it's a routing metric (shorter paths are preferred) and a loop-prevention mechanism (if a router sees its own ASN already in the path, it discards the route).
The Rule: Shorter AS-Path is Better.
If your router sees two paths to reach 8.8.8.0/24 (Google DNS):
- Path A: AS200 → AS300 → AS15169 (Google) — AS-Path length: 3
- Path B: AS400 → AS15169 (Google) — AS-Path length: 2
BGP selects Path B because it has fewer AS hops. This is checked after Local Preference, so it only comes into play when Local Pref values are equal.
AS-Path Prepending is a common traffic engineering technique where a network intentionally repeats its own ASN multiple times in the AS-Path to make a route look less attractive:
AS-Path: 65001 65001 65001 15169
This is used to influence which of your upstream providers carries the majority of inbound traffic — effectively making one path look "longer" to steer traffic toward a preferred entry point.
Loop Prevention: When a BGP router receives an update, it checks whether its own ASN appears anywhere in the AS-Path. If it does, the route is silently discarded. This prevents routing loops from forming across AS boundaries.
Key Point: AS-Path length drives the default BGP path selection when policy attributes are equal, and AS-Path prepending is the primary tool for influencing inbound traffic from external networks.