Prefix Length and Binary Number System
TL;DR
Routers and computers use binary, while humans use decimal numbers, requiring an understanding of both to work with IPv4 addresses. A subnet mask, or its shorthand, the prefix length, defines the network and host parts of an IPv4 address. Correctly understanding subnet masks and prefix lengths is crucial for efficient network segmentation and traffic management.
1. The Mental Model
Think of an IPv4 address as a street address. The network portion is like the street name and block, defining where the whole network lives. The host portion is like the specific house number on that street. The subnet mask, or prefix length, is what tells you exactly where the street name ends and the house number begins.
2. The Core Material
Understanding Binary and IPv4 Addresses
Routers and computers understand information in binary, which is a system of 0s and 1s. Humans, however, typically work in decimal numbers (0-9). An IPv4 address is a 32-bit hierarchical address made up of four blocks, each ranging from 0 to 255. It's split into two main parts: the network portion and the host portion.
Subnet Masks and Prefix Lengths
A subnet mask is essential for determining which part of an IPv4 address is the network and which is the host. It also has a default form for each IP class, which indicates the number of available IP addresses for a given network.
The prefix length is a simpler way to represent the subnet mask. It's written in "slash notation" (e.g., /8, /24). The prefix length tells you the number of bits set to 1 in the subnet mask. An IPv4 address is a 32-bit address. So, a /24 prefix length means the first 24 bits of the subnet mask are 1s, and the remaining 8 bits are 0s.
Here's how subnet masks and prefix lengths relate:
graph TD
A["IPv4 Address (32-bit)"] --> B["Network Portion"];
A["IPv4 Address (32-bit)"] --> C["Host Portion"];
SM["Subnet Mask"] --> B;
SM["Subnet Mask"] --> C;
PL["Prefix Length"] --> SM;
PL === SN["Slash Notation (/N)"];
SM_Bin["Subnet Mask in Binary"] --> PL_Bits["Number of '1' bits"];
PL_Bits --> PL;
For example, a common subnet mask is 255.255.255.0. In binary, this looks like:
11111111.11111111.11111111.00000000
If you count the 1s, there are 24 of them. So, the prefix length for 255.255.255.0 is /24. This means the first 24 bits define the network, and the last 8 bits define t