Learn how subnet masks separate network and host bits, how CIDR prefix lengths describe masks, and how to calculate whether addresses share a subnet.
What you will be able to do
- Define the roles of the network prefix and host portion in an IPv4 address.
- Translate common CIDR prefix lengths into dotted-decimal subnet masks.
- Explain why a prefix boundary can occur inside an octet.
- Apply a subnet mask with logical AND to find a network address.
01
What a subnet mask does
An IPv4 subnet mask is a 32-bit value interpreted alongside an IPv4 address. It separates the address into a network prefix and a host portion.
The network prefix identifies the subnet. The host portion identifies a location within that subnet, so the two parts serve different roles.
The address by itself is incomplete for this purpose. Its mask or prefix length tells you where the classless network boundary lies.
02
Reading mask bits
Each mask bit lines up with one address bit. A one assigns that position to the network prefix, while a zero assigns it to the host portion.
Imagine placing the address and mask in two aligned rows. The mask acts like a boundary guide, showing which positions belong to the subnet and which remain available for hosts.
This bit-level view explains why a mask is more precise than simply looking at the four dotted octets.
03
CIDR notation
CIDR writes the mask as a slash followed by a number, such as /24. That number counts the consecutive one bits beginning at the left side of the mask.
IPv4 prefix lengths run from /0 through /32. A smaller value leaves fewer network bits, while a larger value marks more bits as network bits.
The slash notation is compact, but it still describes the same boundary as a dotted-decimal mask.
04
Common mask patterns
A /8 mask is 255.0.0.0. It contains eight network bits and twenty-four host bits.
A /16 mask is 255.255.0.0. It contains sixteen network bits and sixteen host bits.
A /24 mask is 255.255.255.0. It contains twenty-four network bits and eight host bits.
For smaller blocks, /25, /26, /27, and /28 correspond to 255.255.255.128, 255.255.255.192, 255.255.255.224, and 255.255.255.240.
05
A boundary can split an octet
The dots in an IPv4 address separate octets, but they do not restrict network boundaries to those positions.
For example, /27 uses twenty-seven network bits. Its boundary passes seven bits into the fourth octet, producing the mask 255.255.255.224.
Therefore, read the prefix length as a bit count first. Do not assume every network portion ends after a complete octet.
06
Finding the network address
To find the network address for an address-and-mask pair, apply a logical AND to corresponding address and mask bits.
An AND result is one only when both aligned bits are one. Masked host positions therefore become zero, while matching network bits remain available in the result.
Apply the /27 boundary to 192.168.5.70: clearing its five host bits gives the subnet identifier 192.168.5.64.
07
Testing subnet membership
To compare two IPv4 addresses, use the same mask on both addresses. Calculate each resulting network address separately.
If the two results match, the addresses belong to the same subnet under that mask. If the results differ, they do not share that subnet.
The comparison depends on the mask. Changing the boundary can change the network address produced for an address.
08
Connecting prefix length and block size
Increasing the prefix length moves more bits into the network prefix. Consequently, fewer bits remain in the host portion.
A longer prefix represents a smaller IPv4 address block than a shorter prefix. For instance, /27 is more specific than /24 because it uses more network bits.
This relationship helps you predict the effect of changing a mask before calculating any individual address.
09
Recap before Practice and Prove
A subnet mask divides an IPv4 address into network and host portions. One bits mark the network, and zero bits mark the host portion.
CIDR counts the mask's leftmost contiguous one bits. Prefix lengths range from /0 to /32, and common values map to familiar dotted-decimal masks.
A prefix boundary can fall inside an octet, so read a prefix length as a bit count rather than assuming the boundary follows a dot.
Logical AND finds the network address by preserving the network bits and clearing the host bits.
Two addresses share a subnet under a mask when applying that mask produces the same network address for both.