Next-Hop Calculator
Given a destination IP and a routing table, find the best-match route using the longest-prefix-match rule.
Inputs
The IP address you want to route toward.
One entry per line: network/prefix via next-hop-ip
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
Values used
Destination IP = 10.1.5.42
Longest prefix match rule
select the matching route with the greatest prefix length
Best-Match Route
= 10.1.5.0/24
Next Hop
= 10.1.5.254
Total Matching Routes
= 4
Matched Prefix Length
= 24 /
How it works
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
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.