Longest Prefix Match

  • When a router gets a packet, it has to pick a route from its routing table to decide how to forward it. The routing table can hold many routes, sometimes dozens or even hundreds. Each route stands for a different network.

    Sometimes, a router discovers multiple routes that match the same destination IP address but with different subnet masks. This is when the Longest Prefix Match (LPM) rule is important. This rule helps the router choose the best path for the destination network. It picks the most accurate route instead of a broader, less specific option.

    Example scenario

    Let’s look at an example together.
    A packet with the destination IP address 192.168.1.130 arrives at router R1.

    Longest Prefix Match routing table example in CCNA showing /16, /24 and /25 prefixes

    Figure 1 – Router with multiple matching routes

    When we check the routing table, the router finds three possible matches for this destination:

    • 192.168.0.0/16

    • 192.168.1.0/24

    • 192.168.1.128/25

    At first glance, all three entries seem valid because they all include the destination IP address 192.168.1.130. However, the router must select the most specific route according to the Longest Prefix Match (LPM) principle.

    The router picks the route with the longest prefix. This means it chooses the network that has the most bits in common with the destination address. This method ensures that traffic is always forwarded through the most precise and efficient path available.

    Let’s explore the LPM process step by step in the next section.

    Answer the question below