Back to all notes
Networking• Sep 2026• 6 min read

Subnetting Math: Demystifying CIDR & Host Ranges

How to calculate network addresses, broadcast addresses, and usable host counts from any IPv4 CIDR prefix without guesswork.

#IPv4#Subnetting#CIDR#Routing

What is CIDR?

Classless Inter-Domain Routing (CIDR) replaced the old Class A, B, and C system with a flexible prefix length notation (`/XX`).

An IPv4 address consists of 32 bits, represented as 4 octets separated by dots (e.g., `192.168.1.0`). The prefix length tells you how many of those 32 bits belong to the **Network ID**, while the remaining bits belong to **Host IDs**.


Key Formulas

1. **Total IP Addresses in a Subnet**: $$\text{Total IPs} = 2^{(32 - \text{prefix})}$$

2. **Usable Host Addresses**: $$\text{Usable Hosts} = 2^{(32 - \text{prefix})} - 2$$ *(Subtract 2 because the First address is the Network ID and the Last address is the Broadcast ID)*.


Cheat Sheet: Common Prefix Sizes

PrefixSubnet MaskTotal IPsUsable HostsCommon Use Case
`/30``255.255.255.252`42Point-to-Point Router Links
`/28``255.255.255.240`1614Small Subnet / Cloud DMZ
`/24``255.255.255.0`256254Standard LAN / Home Network
`/20``255.255.240.0`4,0964,094Corporate Branch Network
`/16``255.255.0.0`65,53665,534AWS VPC Primary CIDR Block

Step-by-Step Example: `172.16.50.0/26`

- **Prefix length**: `26` $\rightarrow$ Host bits = $32 - 26 = 6$ bits. - **Total addresses**: $2^6 = 64$ IPs. - **Usable hosts**: $64 - 2 = 62$ hosts. - **Subnet Mask**: `255.255.255.192` - **Network Address**: `172.16.50.0` - **First Usable Host**: `172.16.50.1` - **Last Usable Host**: `172.16.50.62` - **Broadcast Address**: `172.16.50.63`