When several rows match, the row with the longest prefix is chosen.

highlighted = computed this step

Choose the most specific match

After matching rows are known, the router keeps the eligible row with the longest prefix.

winning prefix length=25\text{winning prefix length}=25
The longest match winsThe winner is recomputed from all matching prefixes.Longest prefix match - destination 192.168.1.130, winner 192.168.1.128/25 -> labprefixmaskdest & maskmatchnext hopwinner192.168.0.0/16255.255.0.0192.168.0.0yescoreno192.168.1.0/24255.255.255.0192.168.1.0yesfloor-1no192.168.1.128/25255.255.255.128192.168.1.128yeslabyes0.0.0.0/00.0.0.00.0.0.0yesdefaultno

Longer means more fixed bits

Prefix length 25 fixes more leading address bits than the broader rows.

/25/25
The longest match winsThe winner is recomputed from all matching prefixes.Longest prefix match - destination 192.168.1.130, winner 192.168.1.128/25 -> labprefixmaskdest & maskmatchnext hopwinner192.168.0.0/16255.255.0.0192.168.0.0yescoreno192.168.1.0/24255.255.255.0192.168.1.0yesfloor-1no192.168.1.128/25255.255.255.128192.168.1.128yeslabyes0.0.0.0/00.0.0.00.0.0.0yesdefaultno

The lab row matches exactly

The masked destination for the winning row is 192.168.1.128, matching that row's network.

winner network=192.168.1.128\text{winner network}=192.168.1.128
The longest match winsThe winner is recomputed from all matching prefixes.Longest prefix match - destination 192.168.1.130, winner 192.168.1.128/25 -> labprefixmaskdest & maskmatchnext hopwinner192.168.0.0/16255.255.0.0192.168.0.0yescoreno192.168.1.0/24255.255.255.0192.168.1.0yesfloor-1no192.168.1.128/25255.255.255.128192.168.1.128yeslabyes0.0.0.0/00.0.0.00.0.0.0yesdefaultno

Summary

Longest-prefix match chooses the most specific eligible row.

winner length=25\text{winner length}=25
The longest match winsThe winner is recomputed from all matching prefixes.Longest prefix match - destination 192.168.1.130, winner 192.168.1.128/25 -> labprefixmaskdest & maskmatchnext hopwinner192.168.0.0/16255.255.0.0192.168.0.0yescoreno192.168.1.0/24255.255.255.0192.168.1.0yesfloor-1no192.168.1.128/25255.255.255.128192.168.1.128yeslabyes0.0.0.0/00.0.0.00.0.0.0yesdefaultno