Connected: An Internet Encyclopedia
Tricks of the Trade

Up: Connected: An Internet Encyclopedia
Up: Programmed Instruction Course
Up: Subnetting and CIDR
Prev: Nested Prefixes
Next: Power of Two Blocks

Tricks of the Trade Once you've mastered the theory of IP address prefixes, you quickly grow tired of all the binary conversions. Sometimes you have no choice but to convert a number into binary, but often there is a simpler way. Here are some common cases that simplify IP prefix calculations.

Rule 1: A prefix length of 0 matches anything
A prefix of 0.0.0.0/0, or 0/0, is the shortest possible IP address prefix and matches any IP address. We'll see later how this prefix can used to construct default routes to handle routing in cases where no other information is available.

Rule 2: A prefix length of 32 is an exact match
A prefix length of 32 bits, the width of a complete IP address, is the longest possible address prefix and matches one IP address exactly. 32 bit prefixes are used to construct host routes, which specify routing behavior for a single IP address.

Rule 3: Prefix lengths of 8, 16, and 24 match whole bytes
Any prefix length that's a multiple of 8 matches on byte boundaries. For example, a prefix of 172.30/16 matches any IP address that begins with 172.30 in the first two bytes, and ends with anything in the last two bytes. Similarly, an 8 bit prefix matches the first byte exactly and a 24 bit prefix matches the first three bytes exactly.

Rule 4: You never have to manipulate more than one byte in binary
The prefix boundary must fall within one of the IP address' four bytes, and this is the only byte that must be converted into binary. Prefix lengths less than 8 require the first byte to be examined in binary; the remaining three bytes of the address are ignored since they lie completely beyond the address prefix. Likewise, prefix lengths between 8 and 16 require a binary decomposition on the second byte; the first byte matches exactly and the last two bytes are ignored. Prefix lengths from 16 to 24 fall within the third byte, so the first two bytes match exactly and the last one is ignored. The final case, prefix lengths greater than 24 exactly match the first three bytes and require the fourth to be broken down into ones and zeros.

For example, upon seeing the address prefix 208.130.28/22, you can immediately know that the first two bytes of any matching address must be 208.130, and the fourth byte can be anything. Only the third byte must be studied in detail.


Next: Power of Two Blocks

Connected: An Internet Encyclopedia
Tricks of the Trade