Skip to main content
IP Range CalculatorPRO
IPv4 Subnetting & RangeInstant Client-Side Tool

Longest Prefix Match Calculator

Find the most specific matching route.

Longest Prefix Match Calculator: inputs and results

Enter an IP address, CIDR prefix, or range. Then check its first and last address below.

Quick presets:

Calculated Boundaries & ParametersReady

Network Address192.168.1.0
Broadcast Address192.168.1.255
First Usable Host192.168.1.1
Last Usable Host192.168.1.254
Subnet Mask255.255.255.0
Wildcard Mask0.0.0.255
Total Addresses256
Usable Host Range254

How Longest Prefix Match Calculator Works?

This tool works by testing a destination address against every route in a routing table and selecting the matching route with the longest prefix length.

  1. Enter the routing table

    Paste routes such as 0.0.0.0/0, 10.0.0.0/8, and 10.1.2.0/24.

  2. Enter the destination

    Type a destination address, such as 10.1.2.77.

  3. Find every matching route

    A route matches when destination AND mask equals the route network.

  4. Pick the longest prefix

    Among the matches, the route with the highest prefix length wins. The default route matches everything and wins only when nothing else matches.

Longest Prefix Match Calculator Formula

The formula is Best Route = argmax(p) over routes where (Destination AND Mask(p)) = Route Network.

Match test

(D AND Mask(p)) = N

Runs for every route.

Selection

max(p) among matches

Longer prefixes are more specific.

Default route

0.0.0.0/0 matches every D

The fallback with p = 0.

Worked example: destination 10.1.2.77

0.0.0.0/0      ✓ match (p = 0)
10.0.0.0/8     ✓ match (p = 8)
10.1.0.0/16    ✓ match (p = 16)
10.1.2.0/24    ✓ match (p = 24)
10.1.2.128/25  ✗ (77 < 128)
Best = 10.1.2.0/24

Longest Prefix Match Calculator Conversion Table

The table resolves 10 destination addresses against a 6-route table (0.0.0.0/0, 10.0.0.0/8, 10.1.0.0/16, 10.1.2.0/24, 10.1.2.128/25, 10.1.2.200/32).

DestinationMatching RoutesSelected RoutePrefix Length
10.1.2.77410.1.2.0/24/24
10.1.2.130510.1.2.128/25/25
10.1.2.200610.1.2.200/32/32
10.1.2.201510.1.2.128/25/25
10.1.3.5310.1.0.0/16/16
10.2.0.1210.0.0.0/8/8
10.255.255.255210.0.0.0/8/8
11.0.0.110.0.0.0/0/0
192.168.1.110.0.0.0/0/0
10.1.2.255510.1.2.128/25/25

What is Longest Prefix Match Calculator?

The Longest Prefix Match Calculator is a tool that finds which route a router selects for a destination address, using the longest prefix match rule.

Routers often hold several routes that cover the same destination. RFC 1812 requires the router to pick the most specific one, the route with the most network bits. A /32 beats a /25, a /25 beats a /24, and every specific route beats the /0 default route.

Longest prefix match decides the next hop before administrative distance and metrics apply between routes of equal length. The calculator shows the full candidate list, which explains why traffic takes a given path.

What are the uses of Longest Prefix Match Calculator?

There are 4 main uses of the Longest Prefix Match Calculator, including path troubleshooting, change validation, and traffic engineering.

  • Troubleshooting unexpected paths

    A more-specific route learned from a VPN often overrides a summary. The calculator shows which route wins.

  • Validating route changes

    Before adding a route, engineers test which destinations move to the new path.

  • Designing traffic engineering

    More-specific announcements pull traffic toward a preferred link. The calculator previews the effect.

  • Teaching routing decisions

    Students see every match and the selected route for each destination.