Verified: 2026-10-17By Alex Chen (Lead BGP Architect)RFC 4632 & RFC 302110 Min Read

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.

Host IP Address:192.168.1.130 -> 11000000.10101000.00000001.10000010
Subnet Mask (/26):255.255.255.192 -> 11111111.11111111.11111111.11000000
Bitwise AND Result (Network ID):192.168.1.128 -> 11000000.10101000.00000001.10000000
Subnet Broadcast Address:192.168.1.191 -> 11000000.10101000.00000001.10111111
Usable Host IP Range:192.168.1.129 through 192.168.1.190 (62 usable hosts)

2. Comprehensive CIDR Subnet Reference Table (/8 to /32)

Below is the complete engineering specification for every standard IPv4 subnet mask and CIDR prefix:

IPv4 CIDR Subnet Masks, Wildcards, and Host Densities
CIDR PrefixSubnet MaskWildcard MaskTotal AddressesUsable HostsTypical Practical Use Case
/8255.0.0.00.255.255.25516,777,21616,777,214Historical Class A / Global RIR allocations
/12255.240.0.00.15.255.2551,048,5761,048,574RFC 1918 Private block (172.16.0.0/12)
/16255.255.0.00.0.255.25565,53665,534Historical Class B / Large enterprise campus core
/20255.255.240.00.0.15.2554,0964,094Cloud VPC subnets / Mid-tier ISP allocations
/24255.255.255.00.0.0.255256254Standard office LAN / Default home router DHCP pool
/25255.255.255.1280.0.0.127128126Departmental subnet split (Half of /24)
/26255.255.255.1920.0.0.636462Medium cluster segment / Server farm VLAN
/27255.255.255.2240.0.0.313230Small branch office / DMZ perimeter segment
/28255.255.255.2400.0.0.151614Dedicated firewall cluster / Public static IP pool
/29255.255.255.2480.0.0.786ISP commercial fiber handoff (Gateway + 5 usable)
/30255.255.255.2520.0.0.342Legacy point-to-point link (1 router per side)
/31255.255.255.2540.0.0.122Modern point-to-point link per RFC 3021 (Zero waste)
/32255.255.255.2550.0.0.011Single 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 .0 was discarded as the Subnet ID.
  • Address .1 was assigned to Router A.
  • Address .2 was assigned to Router B.
  • Address .3 was 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:

Linux IP Route Inspection:ip -4 route show dev eth0
Linux Dynamic CIDR Calculation:ipcalc 192.168.1.130/26
Windows PowerShell Subnet Query:Get-NetIPAddress -InterfaceAlias "Ethernet" | Format-Table IPAddress, IPv4Address, PrefixLength
macOS Network Configuration:networksetup -getinfo "Wi-Fi"

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