How to Calculate IPv4 Subnets, Netmasks, and CIDR Blocks (Explained)
IPv4 Subnet & CIDR Calculator
Interactive visual subnet calculator showing binary octets, IP ranges, bitmasks, and RFC 1918 classification.
What Is Subnetting & CIDR?
An IPv4 address is a 32-bit number typically written as four decimal octets separated by dots (e.g., 192.168.1.50).
Before Classless Inter-Domain Routing (CIDR) was standardized in RFC 4632, IPv4 addresses were split into rigid Class A, B, and C blocks, which caused immense IP waste. CIDR introduced variable-length subnet masking using slash notation (/N), where N (between 0 and 32) designates how many bits belong to the network prefix.
The Usable Host Calculation Formula
To calculate the number of assignable host addresses in any subnet:
$$\text{Host Bits } (H) = 32 - \text{CIDR Prefix}$$$$\text{Total Addresses} = 2^H$$$$\text{Usable Hosts} = 2^H - 2$$Why Subtract 2?
- Network Address (All host bits are
0): Identifies the subnet itself on routing tables. - Broadcast Address (All host bits are
1): Sends packets to all hosts on the subnet simultaneously.
CIDR Prefix Reference Table
| CIDR Prefix | Subnet Mask | Total Addresses ($2^H$) | Usable Hosts ($2^H - 2$) | Typical Use Case |
|---|---|---|---|---|
| /30 | 255.255.255.252 | 4 | 2 | Point-to-point router links |
| /29 | 255.255.255.248 | 8 | 6 | Small cloud VPC subnets |
| /28 | 255.255.255.240 | 16 | 14 | Small DMZ / firewall blocks |
| /26 | 255.255.255.192 | 64 | 62 | Departmental LAN |
| /24 | 255.255.255.0 | 256 | 254 | Standard home/office Wi-Fi |
| /23 | 255.255.254.0 | 512 | 510 | Medium enterprise branch |
| /16 | 255.255.0.0 | 65,536 | 65,534 | AWS / Azure Virtual Private Cloud |
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 | Large ISP / National backbones |
Binary Bitmasking: Finding Network and Broadcast IPs
Consider 10.0.15.35/20:
- CIDR /20: 20 ones followed by 12 zeros.
- Subnet Mask:
255.255.240.0. - Host Bits: $32 - 20 = 12 \implies 2^{12} = 4,096$ total IPs ($4,094$ usable hosts).
- Network Address: Bitwise AND of
10.0.15.35and255.255.240.0$\implies \mathbf{10.0.0.0}$. - Broadcast Address: Inverting the mask yields wildcard
0.0.15.255. Bitwise OR with Network IP $\implies \mathbf{10.0.15.255}$. - Usable Range:
10.0.0.1to10.0.15.254.
Eliminate manual subnet math errors with our Toolbox IPv4 Subnet & CIDR Calculator.
Frequently Asked Questions
Why do you subtract 2 when calculating usable hosts in a subnet? ▼
Every standard IPv4 subnet reserves the very first address as the Network Identifier and the very last address as the Subnet Broadcast Address. These two addresses cannot be assigned to individual network interfaces or host machines.
What is CIDR slash notation (e.g., /24)? ▼
Classless Inter-Domain Routing (CIDR) slash notation indicates how many leading bits of the 32-bit IPv4 address belong to the network prefix. For example, /24 means the first 24 bits are 1s (255.255.255.0), leaving 8 bits (2^8 = 256 addresses) for hosts.
What are the standard RFC 1918 private IPv4 ranges? ▼
The three private IP ranges reserved for local networks are: 10.0.0.0/8 (10.0.0.0 – 10.255.255.255), 172.16.0.0/12 (172.16.0.0 – 172.31.255.255), and 192.168.0.0/16 (192.168.0.0 – 192.168.255.255).