Determine which routing table entry wins for a destination using longest prefix match.
Longest prefix match is the fundamental algorithm routers and packet-filtering systems use to decide which of several overlapping CIDR blocks best describes a given IP address: every prefix that numerically covers the address is a candidate match, and among those candidates the one with the longest (most specific) prefix length wins, since it makes the narrowest, most precise claim about that address. This calculator checks every supplied prefix against the target IP, lists every candidate that matches, and highlights the single most specific one that a real router's forwarding table lookup would select.
Longest prefix match selection
among all prefixes P where IP falls within P, select the P with the largest prefix length
CIDR blocks routinely overlap by design — a summary route like 172.16.0.0/16 and a more specific subnet like 172.16.5.0/24 both legitimately cover the same address range, since the /24 is entirely contained within the /16. Longest prefix match resolves this overlap by always preferring the smallest, most specific block that still contains the address.
Yes — it is the core algorithm behind IP-based access control lists, firewall rule evaluation with CIDR-based rules, geolocation-by-IP databases, and any system that needs to resolve which of several overlapping network ranges most specifically describes a given address.
Software and hardware routers typically use specialized data structures — a binary trie (prefix tree) in software, or ternary content-addressable memory (TCAM) in hardware — that can search across every prefix length simultaneously and return the longest match in constant or near-constant time, which is essential for keeping pace with line-rate packet forwarding.