Skip to content
7LayerX

Routing / Field note

BGP path selection: how routers choose a route

Learn how BGP compares routes to the same network, how policy changes the result, and how to check the selected path.

7LayerX Editorialupdated 7 min readBGPIPv4

BGP can learn several routes to the same network. It then selects a preferred route using policy and path attributes. This process is often called best-path selection.

The selected route is not always the physically shortest or fastest route. A network team may prefer one provider because of cost, capacity, security, or business agreements. BGP follows the policy configured by the network operator.

This guide uses a Cisco-style example to explain the common decision points. The exact order and some tie-breaks can differ between vendors, software versions, and configuration.

First, find the matching prefix

Routers use longest-prefix match to forward each packet. If a destination matches both 192.0.2.0/24 and 192.0.2.128/25, the /25 is more specific and wins for addresses inside that range.

That is separate from BGP best-path selection. BGP compares candidate routes for the same prefix. So first confirm that the routes you are comparing are for the same network.

Check that each route can be considered

Before comparing preferences, a router must be able to use a route. A route may be removed by an import policy, rejected by validation policy, contain the router's own AS in its AS_PATH, or have an unreachable next hop. Such a route cannot become the usable best path.

For this reason, “the router learned the route” does not always mean “the router can forward traffic through it.”

The simulator's two-provider example

Corp-X router X1 (AS 64531) learns 192.0.2.0/24 through two providers. Path A comes from ISP-B (AS 64520), and Path B comes from ISP-C (AS 64540). Both routes are eligible, and both next hops are reachable. In the default scenario, both have Local Preference 100, and both AS_PATH values have two AS numbers. Path A wins because its IGP cost to next hop 10.0.2.1 is 10, lower than Path B's cost of 20 to 10.0.4.1.

Corp-X router X1 compares two routes for 192.0.2.0/24. Path A arrives through ISP-B AS 64520 with Local Preference 100 and IGP cost 10. Path B arrives through ISP-C AS 64540 with Local Preference 100 and IGP cost 20. Path A wins on IGP cost.

The Local Preference preset changes this result: Path B's value becomes 200, while Path A stays at 100. Path B then wins at the Local Preference check, before IGP cost is considered. Local Preference is an internal policy signal: a larger number is preferred.

Common best-path checks

The list below is a simplified Cisco-style order. It helps explain many route choices, but it is not a universal sequence for every BGP implementation.

  1. Weight — Cisco-specific and local to one router; higher is preferred.
  2. Local Preference — shared within an AS by iBGP; higher is preferred.
  3. Locally originated route — a route created on this router can be preferred.
  4. AS_PATH length — a shorter path is generally preferred.
  5. ORIGIN — lower is preferred: IGP, then EGP, then incomplete.
  6. MED — lower is generally preferred, with default comparison commonly limited to paths from the same neighboring AS.
  7. eBGP over iBGP — an external path is generally preferred at this stage.
  8. IGP cost to the next hop — lower internal cost is preferred.
  9. Tie-breaks — the router may keep an already selected external path for stability, then compare router ID. A route-reflector cluster list and peer address may be checked later. The details and order depend on the platform and settings.

Some implementations offer additional controls such as AIGP or configurable comparison behavior. Consult the vendor documentation for the exact order on your routers.

What the main attributes tell you

Local Preference: choose an exit from your network

Local Preference is used inside one autonomous system (AS). In the simulator, Corp-X AS 64531 receives Path A from ISP-B with value 100 and Path B from ISP-C with value 100. The Local Preference preset raises Path B to 200, so Corp-X prefers ISP-C. These are example policy values, not protocol defaults.

Local Preference mainly affects outbound traffic leaving your AS. It does not directly command another AS to send traffic to you.

AS_PATH: see the AS sequence

AS_PATH records the autonomous systems a route passed through. In the default simulator scenario, Path A has 64520 64512; Path B has 64540 64512. Both paths contain two AS numbers, so AS_PATH does not decide that result. In the AS_PATH preset, Path A is prepended twice and becomes longer, so Path B wins at this check. Prepending may influence other networks' inbound choices, but those networks remain free to use their own policies.

MED: suggest an entry point to a neighboring AS

Multi-Exit Discriminator (MED) is a hint that can help a neighboring AS choose an entry point to your network. Lower is generally preferred. The simulator's MED preset sets Path A to 50 and Path B to 10, and turns on an explicit comparison across ISP-B and ISP-C. Many implementations compare MED only for routes learned from the same neighboring AS by default, so this preset is a teaching override rather than a universal default.

MED is a suggestion, not a guarantee. The receiving network controls its own route policy.

NEXT_HOP: the route must be reachable

NEXT_HOP identifies where traffic should go next. It is a reachability requirement, not simply a “higher is better” preference value. At Corp-X X1, Path A uses next hop 10.0.2.1 and Path B uses 10.0.4.1. If X1 cannot resolve a next hop, it cannot use that path. With iBGP, the next hop is often preserved; next-hop-self is commonly used to make an internal router advertise itself as the next hop.

Route validation and multipath

RPKI origin validation can label a route Valid, Invalid, or NotFound. Operators may use that result in policy to reject a route or change its preference. RPKI validation is not a universal extra step in the BGP best-path list; its effect depends on the network's configuration.

Some networks install multiple equal or sufficiently similar paths for load sharing, often called multipath or ECMP. This is a platform and policy feature. It does not mean that every BGP router forwards over every route it learns.

Also distinguish the BGP best path from the route used for forwarding. A platform may select a BGP path that then loses to another routing source under its route-preference rules. Check both the BGP table and the main routing table.

A practical way to investigate a route

On Cisco IOS-style equipment, these commands can help. Other platforms use different commands and output formats.

show ip bgp 192.0.2.0/24
show ip route 192.0.2.0
show ip bgp neighbors 10.0.2.1 received-routes
show ip bgp neighbors 10.0.4.1 received-routes

Start with the exact prefix. Then check which paths are present, whether each next hop is reachable, and whether import policy or route validation removed a candidate. Compare the attributes in the platform's best-path order; the first meaningful difference often explains the decision. Finally, check whether the chosen BGP path was installed for forwarding.

Common questions about BGP path selection

Quick answers about BGP route choices, path attributes, and traffic direction. Open a question to see the answer.

4 answers

Does BGP choose the route with the lowest latency?

No. BGP does not normally measure end-to-end latency as its basic best-path rule. Policy, path attributes, and the internal cost to the next hop influence selection. A team can build latency-aware policy, but it must configure or add that behavior.

Does a shorter AS_PATH always win?

No. Attributes earlier in the configured decision order can decide the result first. In the example above, ISP-B wins on Local Preference even though its AS_PATH is longer.

Can I use Local Preference to control traffic coming into my AS?

Local Preference controls route choice inside your own AS, so it mainly affects traffic leaving your AS. To influence inbound traffic, operators may use tools such as AS_PATH prepending or MED, but the neighboring networks make the final decision.

Will every router select the same path?

Not necessarily. Routers can receive different routes or have different policies and configurations. Local Preference is normally shared across an AS through iBGP, but other inputs and route-reflector design can still affect what each router knows and selects.

Pass it along

Found this useful? Share it.

Choose a platform or copy the direct link.

LinkedInXFacebook

Continue reading

Reader signal

Was this useful?

Your feedback helps shape the next field note and lab.

… views

Views count when this page opens. You can change or remove your vote during this tab session.