I understand the concept and how the longest prefix match rule works.

Let's say a router receives a packet destined for and the router has the following matching routes in its routing table. enter image description here

It will pick and use the static route, because it's the most specific route/has the longest prefix length.

However, why does it work like this? What is the reasoning behind it? Would any problems occur it it chose one of the less-specific routes?

Thank you all in advance.

  • Interesting bit of screenshot/output, there. Ist that an actual thing? "S" usually stands for "static" and a combination of static routes as shown is possible. But further down each line it says "directly connected" (which in turn should've made it a "C" at the beginning) and all subnets seem connected to the same interface Gig0/0/0. You can't usually configure overlapping subnets on a router's interfaces. Can I bother you to show us the config section that lead to such a routing table? Mar 29, 2023 at 21:15
  • The reason why it says "Directly Connected" is because this is a Directly Connected Static Route. In such routes, we only specify the output interface. cisco.com/c/en/us/td/docs/switches/datacenter/nexus3000/sw/…
    – Mitrixsen
    Mar 30, 2023 at 12:01
  • Directly connected routes usually have "C" at the beginning of the line. "S", as in your output - denotes "static", but that contradicts with "is directly connected". Mar 31, 2023 at 14:59

2 Answers 2


Would any problems occur it it chose one of the less-specific routes?

Yes. Your PC is a good example. You (usually) have two routes in your PC's routing table. It will look something like this:

    Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
     25         On-link    281

Let's say you have a printer on your desk with an IP address of If you send data to it, which route will your PC use? If you use the most specific route (, the data will be sent to the printer on the local subnet. But if you use the least-specific route, the data will be sent to the default gateway instead of your printer.

Since most devices have a default route (, all data will always use the default route, since it is the least specific match. The PC or router would never choose any other route than the default.


The longest-prefix-preferred rule saves you the hassle to finely split up all routing into distinct routes (if no overlap would be allowed) and use a coarser, "catch-all" route instead.

A good use case to show why that scheme is a good idea is a corporation network using overall and where a branch location may have multiple VPN/MPLS links and sends to one site, to another, and to HQ where it may or may not be forwarded elsewhere.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.