Subnet Mask and Prefix Length Guide: From /8 to /32 Explained
A comprehensive networking reference for Classless Inter-Domain Routing (CIDR), bitwise subnet masking, host capacity formulas, and practical IP prefix allocation.
Quick Answer
A subnet mask is a 32-bit binary filter that divides an IPv4 address into two distinct components: the Network Identifier and the Host Identifier. Expressed in CIDR prefix notation (/n), the prefix length indicates the exact number of contiguous leading 1-bits in the mask, directly determining the network boundary and the total number of assignable IP addresses.
- CIDR Formula: Total IPs = 2^(32 - prefix); Usable Hosts = Total IPs - 2 (except /31 and /32).
- Standard LAN: /24 (255.255.255.0) provides 254 usable host addresses.
- Point-to-point optimization: RFC 3021 allows /31 prefixes on router links without wasting broadcast/network IDs.
1. Bitwise Arithmetic: How Routers Evaluate Subnets
Every network device computes its broadcast boundary and determines whether a destination address is local or remote by performing a bitwise logical AND operation between the target IP address and its configured subnet mask.
2. Comprehensive CIDR Subnet Reference Table (/8 to /32)
Below is the complete engineering specification for every standard IPv4 subnet mask and CIDR prefix:
| CIDR Prefix | Subnet Mask | Wildcard Mask | Total Addresses | Usable Hosts | Typical Practical Use Case |
|---|---|---|---|---|---|
| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,216 | 16,777,214 | Historical Class A / Global RIR allocations |
| /12 | 255.240.0.0 | 0.15.255.255 | 1,048,576 | 1,048,574 | RFC 1918 Private block (172.16.0.0/12) |
| /16 | 255.255.0.0 | 0.0.255.255 | 65,536 | 65,534 | Historical Class B / Large enterprise campus core |
| /20 | 255.255.240.0 | 0.0.15.255 | 4,096 | 4,094 | Cloud VPC subnets / Mid-tier ISP allocations |
| /24 | 255.255.255.0 | 0.0.0.255 | 256 | 254 | Standard office LAN / Default home router DHCP pool |
| /25 | 255.255.255.128 | 0.0.0.127 | 128 | 126 | Departmental subnet split (Half of /24) |
| /26 | 255.255.255.192 | 0.0.0.63 | 64 | 62 | Medium cluster segment / Server farm VLAN |
| /27 | 255.255.255.224 | 0.0.0.31 | 32 | 30 | Small branch office / DMZ perimeter segment |
| /28 | 255.255.255.240 | 0.0.0.15 | 16 | 14 | Dedicated firewall cluster / Public static IP pool |
| /29 | 255.255.255.248 | 0.0.0.7 | 8 | 6 | ISP commercial fiber handoff (Gateway + 5 usable) |
| /30 | 255.255.255.252 | 0.0.0.3 | 4 | 2 | Legacy point-to-point link (1 router per side) |
| /31 | 255.255.255.254 | 0.0.0.1 | 2 | 2 | Modern point-to-point link per RFC 3021 (Zero waste) |
| /32 | 255.255.255.255 | 0.0.0.0 | 1 | 1 | Single host route / Loopback interface / Blackhole |
Subnet Mask Selection Decision Tree
[ Desired Number of Usable Host Devices ]
|
+-----------------------+-----------------------+
| | |
[ 1 Host ] [ 2 Hosts ] [ 3-6 Hosts ]
Use /32 Route Point-to-Point Link? Use /29
255.255.255.255 /31 (RFC 3021 Router) 255.255.255.248
Host / Loopback or /30 (Legacy WAN) 8 Total / 6 Usable
| | |
+-----------------------+-----------------------+
|
+-----------------------+-----------------------+
| | |
[ 7-14 Hosts ] [ 15-30 Hosts ] [ 31-254 Hosts ]
Use /28 Use /27 Use /24 - /26
255.255.255.240 255.255.255.224 Standard Office LAN
16 Total / 14 Usable 32 Total / 30 Usable 64 to 256 Total IPs
3. Modern Point-to-Point Links: The RFC 3021 Advantage
Before RFC 3021, network architects were forced to allocate a /30 subnet for every dedicated serial or fiber connection between two routers. Out of 4 addresses:
- Address
.0was discarded as the Subnet ID. - Address
.1was assigned to Router A. - Address
.2was assigned to Router B. - Address
.3was discarded as the Broadcast address.
This created a 50% waste of valuable IPv4 space. RFC 3021 revised this rule for point-to-point links by stipulating that broadcast packets are irrelevant when only two endpoints exist. With a /31 mask (255.255.255.254), both addresses are directly assignable, conserving millions of public IPv4 addresses across global telecommunication backbones.
4. Practical Terminal Commands: Verifying Subnets
Inspect, calculate, and modify subnet parameters using standard command-line tools:
Frequently Asked Questions
Why do most subnets lose 2 IP addresses from their total capacity?
In standard IPv4 subnets (/30 and larger), the first address (all host bits 0) is reserved as the Subnet Network Identifier, and the final address (all host bits 1) is reserved as the Directed Broadcast Address. Devices cannot be assigned either address, resulting in usable hosts = 2^(32-prefix) - 2.
How does RFC 3021 permit using a /31 prefix for point-to-point router links?
RFC 3021 eliminates the requirement for network and broadcast addresses on strictly point-to-point links (such as router-to-router interconnects). Because only two endpoints exist on the physical wire, directed broadcast is unnecessary, allowing both addresses (e.g., .0 and .1) to be assigned as valid host interfaces, conserving 50% of address space compared to /30.
What is a wildcard mask and how does it relate to a subnet mask?
A wildcard mask is the bitwise inverse (NOT operation) of a subnet mask. Where a subnet mask has 1s to match network bits, a wildcard mask has 0s; where the subnet mask has 0s for host bits, the wildcard mask has 1s. For example, a /24 subnet mask is 255.255.255.0, and its wildcard mask is 0.0.0.255, commonly used in Cisco ACLs and OSPF area configurations.
What does a /32 subnet mask represent in routing tables?
A /32 prefix (subnet mask 255.255.255.255) defines an explicit single-host route. It has zero host bits and specifies one exact device interface or loopback IP address. Operating systems and BGP edge routers use /32 routes for precision routing and blackhole/null filtering.
Data & Technical Sources
- IETF RFC 4632 — Classless Inter-domain Routing (CIDR): The Internet Address Assignment and Aggregation Plan
- IETF RFC 3021 — Using 31-Bit Prefixes on IPv4 Point-to-Point Links
- IETF RFC 950 — Internet Standard Subnetting Procedure