BGP exchanges network topology information for routers to learn the best paths to IP Prefixes. Unlike IGPs and their use of metrics, BGP uses path attributes (PA) in the decision process when choosing the best possible routes when multiple routes exist to the same destination network.
BGP falls back to using the Autonomous System Path (AS Path) as its default metric mechanism when non of the other PAs have been overly set and configured.
BGP will look at the AS Path to determine the shortest distance to a prefix and verify the sequence of AS’s to ensure its own AS is not included in the path already. This would indicate a possible routing loop and the route would not be accepted.
If its own AS is not in the path sequence, the number of AS hops will determine best path (shortest) to a destination.