Next Hop Calculator
Determine the next-hop gateway for a destination based on the routing table entries.
About Next Hop Calculator
When multiple routes in a routing table could carry traffic to the same destination, routers always select the route with the longest (most specific) matching prefix, regardless of administrative distance or metric — that comparison only happens between routes of equal prefix length. This calculator checks the destination IP against every entry in the supplied table, keeps every route whose network/prefix covers that address, and reports the one with the longest prefix as the actual route the router would use.
Formula
Longest prefix match rule
select the matching route with the greatest prefix length
- p(r)
- Prefix length of matching route r
Worked example
With the default values below, Next Hop Calculator returns Best-Match Route of 10.1.5.0/24. Change any input above and every figure here is recalculated in your browser.
Inputs used
- Destination IP
- 10.1.5.42
- Routing Table Entries
- 0.0.0.0/0 via 192.168.1.1 10.0.0.0/8 via 10.0.0.1 10.1.0.0/16 via 10.1.0.1 10.1.5.0/24 via 10.1.5.254
Results
- Best-Match Route
- 10.1.5.0/24
- Next Hop
- 10.1.5.254
- Total Matching Routes
- 4
- Matched Prefix Length
- 24 /
Step by step
- 1Values used
- 2Longest prefix match rule
- 3Best-Match Route= 10.1.5.0/24
- 4Next Hop= 10.1.5.254
- 5Total Matching Routes= 4
- 6Matched Prefix Length= 24 /
Assumptions and limits
- The result is derived only from the 2 inputs listed above. Anything not among them is not part of the calculation.
- In particular, this calculator does not take inflation, tax, fees or charges or compounding frequency into account.
- Figures are rounded for display to whole numbers, so totals built from several rounded parts can differ slightly from the unrounded arithmetic.
How these calculators are built and tested is described on the Methodology page. If a figure looks wrong, please report it.
Frequently Asked Questions
What is longest prefix match and why does it decide the winning route?
Longest prefix match is the rule that when a destination address matches multiple routes of different specificity, the router always chooses the most specific (longest prefix) one, because a longer prefix describes a smaller, more precisely targeted network and is assumed to be the more accurate path for that destination.
Does the default route (0.0.0.0/0) ever win over a more specific route?
No — the default route has the shortest possible prefix (/0) and will only be selected when no other, more specific route matches the destination at all. It exists purely as a catch-all fallback for traffic to destinations not explicitly known.
How does administrative distance relate to this lookup?
Administrative distance is only used to choose between multiple routes to the exact same destination prefix learned from different sources (e.g. both OSPF and static). It never overrides longest prefix match — a router will always prefer a more specific /24 route over a less specific /16 route to the same address, even if the /16 came from a lower-AD source.
