Jump to content

Longest prefix match: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
No edit summary
corrected subnet mask [MaKno]
Line 7: Line 7:
For example, consider this [[IPv4]] routing table ([[CIDR notation]] is used):
For example, consider this [[IPv4]] routing table ([[CIDR notation]] is used):


192.168.20.16/28
192.168.20.16/24
192.168.0.0/16
192.168.0.0/16


When the address <tt>192.168.20.19</tt> needs to be looked up, both entries in the routing table "match". That is, both entries contain the looked up address. In this case, the longest prefix of the candidate routes is <tt>192.168.20.16/28</tt>, since its [[subnet mask]] (/28) is higher than the other entry's mask (/16), making the route more specific.
When the address <tt>192.168.20.19</tt> needs to be looked up, both entries in the routing table "match". That is, both entries contain the looked up address. In this case, the longest prefix of the candidate routes is <tt>192.168.20.16/24</tt>, since its [[subnet mask]] (/24) is higher than the other entry's mask (/16), making the route more specific.


Routing tables often contain a [[default route]], which has the shortest possible prefix match, to fall back on in case matches with all other entries fail.
Routing tables often contain a [[default route]], which has the shortest possible prefix match, to fall back on in case matches with all other entries fail.

Revision as of 10:54, 11 April 2011

Longest prefix match (also called Maximum prefix length match) refers to an algorithm used by routers in Internet Protocol (IP) networking to select an entry from a routing table [Computer Networks and Internets,Douglas Comer, 2008, p.368].

Because each entry in a routing table may specify a network, one destination address may match more than one routing table entry. The most specific table entry — the one with the highest subnet mask — is called the longest prefix match. It is called this because it is also the entry where the largest number of leading address bits in the table entry match those of the destination address.

For example, consider this IPv4 routing table (CIDR notation is used):

192.168.20.16/24
192.168.0.0/16

When the address 192.168.20.19 needs to be looked up, both entries in the routing table "match". That is, both entries contain the looked up address. In this case, the longest prefix of the candidate routes is 192.168.20.16/24, since its subnet mask (/24) is higher than the other entry's mask (/16), making the route more specific.

Routing tables often contain a default route, which has the shortest possible prefix match, to fall back on in case matches with all other entries fail.

See also