How to Calculate Subnet Masks
March 22, 2026 · 10 min read
Subnetting is one of those networking topics that seems intimidating until you understand the binary math behind it. Whether you're studying for the CCNA, configuring a VPC in AWS, or just trying to figure out why two devices can't talk to each other — understanding subnet masks is essential.
This guide teaches you to calculate subnet masks by hand, explains CIDR notation, and gives you the formulas to quickly determine network addresses, broadcast addresses, and host ranges.
What Is a Subnet Mask?
A subnet mask tells a device which part of an IP address identifies the network and which part identifies the host. It's a 32-bit number, just like an IPv4 address, written in the same dotted-decimal format.
The subnet mask works like a stencil: where the mask has 1 bits, the IP address bits belong to the network portion. Where the mask has 0 bits, the IP address bits belong to the host portion.
CIDR Notation
Instead of writing out the full subnet mask, CIDR (Classless Inter-Domain Routing) notation uses a slash followed by the number of network bits:
| CIDR | Subnet Mask | Binary | Usable Hosts |
|---|---|---|---|
| /8 | 255.0.0.0 | 11111111.00000000.00000000.00000000 | 16,777,214 |
| /16 | 255.255.0.0 | 11111111.11111111.00000000.00000000 | 65,534 |
| /24 | 255.255.255.0 | 11111111.11111111.11111111.00000000 | 254 |
| /25 | 255.255.255.128 | 11111111.11111111.11111111.10000000 | 126 |
| /26 | 255.255.255.192 | 11111111.11111111.11111111.11000000 | 62 |
| /27 | 255.255.255.224 | 11111111.11111111.11111111.11100000 | 30 |
| /28 | 255.255.255.240 | 11111111.11111111.11111111.11110000 | 14 |
| /30 | 255.255.255.252 | 11111111.11111111.11111111.11111100 | 2 |
| /32 | 255.255.255.255 | 11111111.11111111.11111111.11111111 | 1 |
The Key Formulas
Three formulas let you calculate everything you need:
The - 2 in the usable hosts formula accounts for the network address (all host bits = 0) and broadcast address (all host bits = 1), which can't be assigned to devices.
Step-by-Step: Calculate Network and Broadcast Addresses
Let's work through 192.168.1.100/26:
Step 1: Convert to Binary
Step 2: Find the Network Address (AND operation)
Perform a bitwise AND between the IP and the mask. This zeros out the host bits:
Step 3: Find the Broadcast Address
Set all host bits to 1:
Step 4: Determine the Host Range
The Quick Method (No Binary Needed)
For common subnets, you can skip binary entirely using the block size method:
- Find the block size: 256 - subnet mask octet value
- The network address is the nearest multiple of the block size below the IP
- The broadcast address is network address + block size - 1
For 192.168.1.100/26:
Common Subnetting Scenarios
Splitting a /24 into smaller subnets
You have 10.0.0.0/24 and need 4 equal subnets:
Cloud VPC subnetting (AWS/GCP/Azure)
Cloud providers typically recommend:
- /16 VPC — 65,534 addresses for the entire VPC
- /24 subnets — 254 hosts per subnet (one per availability zone)
- /28 minimum — AWS requires at least /28 for subnets (14 usable IPs, minus 5 AWS reserves = 11)
Subnet Mask Cheat Sheet
| CIDR | Mask | Block Size | Hosts | Use Case |
|---|---|---|---|---|
| /30 | 255.255.255.252 | 4 | 2 | Point-to-point links |
| /28 | 255.255.255.240 | 16 | 14 | Small office, AWS minimum |
| /27 | 255.255.255.224 | 32 | 30 | Department LAN |
| /26 | 255.255.255.192 | 64 | 62 | Medium office |
| /25 | 255.255.255.128 | 128 | 126 | Large department |
| /24 | 255.255.255.0 | 256 | 254 | Standard LAN, cloud subnet |
| /16 | 255.255.0.0 | 65,536 | 65,534 | Cloud VPC, campus network |
Subnetting with Python
Python's ipaddress module makes subnetting trivial:
JavaScript Subnetting
Enter any IP and CIDR prefix — get network address, broadcast, host range, and more.
Open Subnet Calculator
Related Reading
- How to Convert Between Number Systems — binary, decimal, hex conversions used in subnetting
- Online Calculator Tools for Developers — subnet calculator and more
- Networking Tools — IP lookup, subnet calculator, HTTP status codes
- IP Address Lookup — find geolocation and ISP info for any IP