Glossary

What is an AS path (AS_PATH)?

AS_PATH is the BGP attribute listing the autonomous system numbers a prefix traversed. It detects loops, shapes best-path selection and enables prepending.

Last updated:

An AS path (AS_PATH) is a mandatory, well-known BGP attribute that holds an ordered list of the autonomous system numbers a prefix advertisement traversed on its way from the origin to the receiver. Each time a route leaves one AS and enters the next over an eBGP session, the router prepends its own AS number to the front of the list. AS_PATH is therefore a record of the path taken, a loop-detection mechanism, and one of the tie-breakers in best-path selection. The attribute is defined in RFC 4271.

How the AS path is built

When an AS originates its own prefix, the AS path is empty or contains only its number. At every eBGP boundary crossing the router adds its AS number to the left of the list, so the nearest neighbour sits at the front and the origin AS at the end. Over iBGP sessions the attribute is left unmodified. AS_PATH consists of two segment types. AS_SEQUENCE is an ordered list reflecting the actual path, and AS_SET is an unordered set used when prefixes are aggregated. Modern networks use four-byte AS numbers as defined in RFC 6793.

Loop prevention

AS_PATH is the primary loop-prevention mechanism in eBGP. When a router receives an advertisement whose AS path already contains its own AS number, it discards the route, because accepting it would loop traffic back on itself. This path-vector approach is more robust than the hop counters used by distance-vector protocols.

  • A router rejects a route if it sees its own AS number anywhere in the AS_PATH.
  • The mechanism works between autonomous systems (eBGP), not within a single AS.
  • Inside an AS, loops are prevented differently: by the rule that iBGP-learned routes are not re-advertised to other iBGP peers, and by route reflectors using the ORIGINATOR_ID and CLUSTER_LIST attributes.
  • The allowas-in option deliberately disables this check and should be used carefully, for example in hub-and-spoke MPLS VPN designs.

Path length in best-path selection

When a router learns several routes to the same prefix, BGP picks a single best path using a fixed order of attributes. After the local weight and the LOCAL_PREF attribute, the next tie-breaker is AS path length: a shorter path, meaning fewer autonomous systems traversed, is preferred. Only when lengths are equal do later attributes decide, such as ORIGIN type, MED, or a preference for eBGP over iBGP. AS_PATH length is a topological heuristic, not a measure of real latency or bandwidth.

AS path prepending in practice

Prepending means deliberately adding your own AS number to the path several times to lengthen it artificially and discourage neighbours from choosing that route. It is the simplest inbound traffic-engineering tool. By advertising the same prefix to two providers, you can add a few copies of your AS number on one link so that traffic enters mainly via the other, shorter path. Prepending is only a hint, though, because a remote operator's LOCAL_PREF outranks AS path length, and excessive prepending is often ignored or filtered. BGP communities offer more precise control.

AS_PATH on the AS202520 SkyPass network

At SkyPass (AS202520) AS_PATH is a day-to-day traffic-steering tool for our peering and transit customers. Routes we advertise carry AS202520 at the front of the path, and multihomed customers can use prepending or our BGP communities to balance traffic between our Warsaw and Wrocław PoPs and our peering at the Polish exchanges THINX, TPIX, WRIX, POZIX and 1-IX. You can inspect the current AS path for any prefix in our looking glass, which makes it easy to verify routing policy and troubleshoot.

Frequently asked questions

How does AS_PATH differ from AS path length?

AS_PATH is the whole attribute containing the list of AS numbers a prefix traversed. AS path length is simply the count of autonomous systems in that list, used as a tie-breaker in best-path selection after weight and LOCAL_PREF.

Does a shorter AS path always mean a faster connection?

No. AS_PATH length counts hops between autonomous systems, not actual latency or bandwidth. A topologically shorter path can have higher latency than a longer but better-provisioned route.

How many times should I prepend?

One to three prepends is usually enough. Larger values rarely help, because a remote operator's LOCAL_PREF outranks path length and some operators filter excessively long AS paths.

How does AS_PATH prevent loops in BGP?

An eBGP router rejects any route in which it already sees its own AS number, since accepting it would close a loop. This is the primary safeguard against traffic looping between autonomous systems.

Related articles