Network guides
Subnetting Explained: How IP Subnet Masks Divide a Network
Every device on a network needs an IP address, but those addresses are not handed out one by one. Networks are split into blocks called subnets, and the tool that defines the boundary of each block is the subnet mask. Understanding subnetting is what turns a confusing string of numbers into a clear map of your network.
In this guide we break down how a subnet mask works, what CIDR notation means in practice, how to count the usable hosts in a subnet, and how large networks are carved up or merged together. By the end you will be able to read a subnet like a network engineer.
-
1981
IPv4 and the birth of classful addressing
RFC 791 defines IPv4 and introduces the classful scheme, dividing addresses into fixed A, B and C classes with rigid network boundaries.
-
1993
CIDR replaces the class system
RFC 1519 introduces Classless Inter-Domain Routing, allowing arbitrary prefix lengths and ending the wasteful fixed-class approach.
-
1995
Variable-length subnet masks
VLSM lets a single network use different mask sizes, making address allocation far more flexible and efficient.
-
Today
Careful subnetting under IPv4 scarcity
With IPv4 exhausted, precise subnetting is essential for conserving addresses, while IPv6 brings a return to generous address space.
What is a subnet mask?
A subnet mask is a 32-bit number that sits next to an IP address and decides which part identifies the network and which part identifies the host. Bits set to 1 mark the network portion, while bits set to 0 mark the range of hosts available within that network. Two devices that share the same network part are on the same subnet.
The mask is written like an IP address, for example 255.255.255.0, and it is the router's guide to how far traffic can travel before it must be forwarded elsewhere. Devices on the same subnet can talk directly, while traffic to another subnet is handed to a router. Changing the mask reshapes the whole network.
From masks to CIDR notation
CIDR notation expresses the same information as a mask, but far more compactly. Instead of 255.255.255.0 you write /24, where the number is the count of 1-bits in the mask. This is why a /24, a /16 and a /8 correspond to different network sizes, from a small office to the public internet.
The slash number tells you how many bits are fixed for the network. A /24 leaves 8 bits for hosts, a /16 leaves 16, and a /8 leaves 24. More network bits mean fewer hosts, so choosing a prefix is a trade-off between the number of subnets you need and the hosts each one must hold.
How many hosts can a subnet hold?
To count usable hosts, you first work out the number of host bits by subtracting the prefix length from 32, then raise two to that power. A /24 has 8 host bits, so it covers 2^8, or 256, total addresses. The formula 2^hostbits gives the whole block, but not every address can be assigned to a device.
The very first address is the network identifier and the very last is the broadcast address, so the usable hosts are 2^hostbits minus 2. A /24 therefore holds 254 usable hosts. For a point-to-point link a /30 is the common choice, leaving exactly two addresses so each end gets one.
Supernetting: merging networks back together
Supernetting is the opposite of subnetting. Instead of carving one block into smaller pieces, it merges several contiguous subnets into one larger block by borrowing bits back from the host portion. This is how providers summarize many customer routes into a single advertised network, keeping the global routing table small and efficient.
The practical benefit is route summarization: fewer routes mean smaller tables and faster forwarding across the internet. A classic example is aggregating two /24 networks into a single /23, which covers both with one entry. Used well, subnetting and supernetting let you design networks that scale cleanly without wasting address space.
要点总结
Subnetting is one of the most useful skills for anyone working with networks. Once you can read a mask and a CIDR prefix, you understand how IP space is organized, how many devices a subnet supports, and how large networks are summarized into manageable routes.