How to Calculate IPv4 Subnets, Netmasks, and CIDR Blocks (Explained)

Sep 4, 2026·
toolbox-editorial-team
· 3 min read
blog

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?

  1. Network Address (All host bits are 0): Identifies the subnet itself on routing tables.
  2. Broadcast Address (All host bits are 1): Sends packets to all hosts on the subnet simultaneously.

CIDR Prefix Reference Table

CIDR PrefixSubnet MaskTotal Addresses ($2^H$)Usable Hosts ($2^H - 2$)Typical Use Case
/30255.255.255.25242Point-to-point router links
/29255.255.255.24886Small cloud VPC subnets
/28255.255.255.2401614Small DMZ / firewall blocks
/26255.255.255.1926462Departmental LAN
/24255.255.255.0256254Standard home/office Wi-Fi
/23255.255.254.0512510Medium enterprise branch
/16255.255.0.065,53665,534AWS / Azure Virtual Private Cloud
/8255.0.0.016,777,21616,777,214Large ISP / National backbones

Advertisement Sponsored

Binary Bitmasking: Finding Network and Broadcast IPs

Consider 10.0.15.35/20:

  1. CIDR /20: 20 ones followed by 12 zeros.
  2. Subnet Mask: 255.255.240.0.
  3. Host Bits: $32 - 20 = 12 \implies 2^{12} = 4,096$ total IPs ($4,094$ usable hosts).
  4. Network Address: Bitwise AND of 10.0.15.35 and 255.255.240.0 $\implies \mathbf{10.0.0.0}$.
  5. Broadcast Address: Inverting the mask yields wildcard 0.0.15.255. Bitwise OR with Network IP $\implies \mathbf{10.0.15.255}$.
  6. Usable Range: 10.0.0.1 to 10.0.15.254.

Eliminate manual subnet math errors with our Toolbox IPv4 Subnet & CIDR Calculator.

Interactive Workbench LIVE

Calculate IPv4 Subnets, Netmasks, and CIDR Blocks (Explained)

Interactive visual subnet calculator showing binary octets, IP ranges, bitmasks, and RFC 1918 classification.
Initializing Workbench...
100% Client-Side RAM Sandbox
🔒 Private Execution: Zero server uploads.
FAQ

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).