The Longest Match Rule

One of the the concepts that comes up occasionally is that of precedence. For example, one might consider the following routing table entries.

ip route              //default route
ip route      //supernet/cidr route
ip route    //network route
ip route  //subnet route
ip route //host route

Questions often arise around which path a packet would take when it matches more than one entry. For example, a packet may have a destination address of In this case it matches every single route entry.

The logic is actually simple, even straightforward. A packet will follow the most specific route entry that it matches. So a packet destined to would be routed to a router at If the destination happened to be, it would be routed over to

As a personal challenge, think about where packets with the following destinations might be routed:


As with everything, there can be some exceptions to the rule. I think one could contrive interesting examples with recursive routes. Another exception is when no ip classless has been configured on the router.

In that case, the rule only has a minor change. When using no ip classless, a packet will only use the default route when there are no subnets of its classful network. That process is describe in detail in Classful Routing With-no ip classless.

Disclaimer: This article includes the independent thoughts, opinions, commentary or technical detail of Paul Stewart. This may or may does not reflect the position of past, present or future employers.

About Paul Stewart, CCIE 26009 (Security)

Paul is a Network and Security Engineer, Trainer and Blogger who enjoys understanding how things really work. With over 15 years of experience in the technology industry, Paul has helped many organizations build, maintain and secure their networks and systems.
This entry was posted in Design. Bookmark the permalink.

3 Responses to The Longest Match Rule

  1. Tommy says:

    Can you explain this one line more…..The rest I understand, but this threw me….”If the destination happened to be, it would be routed over to″

  2. Pingback: Discard Routing for RFC1918 Addresses - PacketU

Comments are closed.