Subnetting Guide — How to Calculate Subnet Masks and IP Ranges
Subnetting divides a network into smaller subnetworks. Here's how CIDR notation, subnet masks, and IP address ranges work — with calculation examples and a cheat sheet.
Subnetting divides a large IP address block into smaller networks. You subnet when you need to organize a network, limit broadcast traffic, control routing, or allocate address ranges to teams, VLANs, or cloud VPCs.
Use the Subnet Calculator to calculate subnet masks, network addresses, broadcast addresses, and usable IP ranges from any CIDR notation.
IP addresses and binary
IPv4 addresses are 32 bits, written as four decimal octets: 192.168.1.1.
192 .168 .1 .1
11000000 .10101000 .00000001 .00000001
Every IPv4 address is a 32-bit binary number. The binary representation is what subnet masks operate on.
Subnet masks
A subnet mask defines which part of an IP address is the network portion and which is the host portion.
Subnet mask 255.255.255.0:
255.255.255.0
11111111.11111111.11111111.00000000
← Network (24 bits) → ← Host (8 bits) →
All the 1 bits in the mask identify the network portion. All the 0 bits identify the host portion.
With a 255.255.255.0 mask:
- The network address is the IP address with all host bits set to 0
- The broadcast address is the IP address with all host bits set to 1
- Usable hosts are everything in between
Example: 192.168.1.0/24
IP address: 192.168.1.0 = 11000000.10101000.00000001.00000000
Subnet mask: 255.255.255.0 = 11111111.11111111.11111111.00000000
Network: 192.168.1.0 (host bits = 00000000)
Broadcast: 192.168.1.255 (host bits = 11111111)
Usable hosts: 192.168.1.1 to 192.168.1.254
Host count: 254 (2^8 - 2 = 254)
Subtract 2 because the network address and broadcast address are not usable.
CIDR notation
CIDR (Classless Inter-Domain Routing) notation appends a prefix length to the IP address: 192.168.1.0/24.
The /24 means “24 bits are the network portion” — equivalent to mask 255.255.255.0.
| CIDR | Subnet mask | Usable hosts | Block size |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,214 | Class A |
| /16 | 255.255.0.0 | 65,534 | Class B |
| /24 | 255.255.255.0 | 254 | Class C |
| /25 | 255.255.255.128 | 126 | Half of /24 |
| /26 | 255.255.255.192 | 62 | Quarter of /24 |
| /27 | 255.255.255.224 | 30 | |
| /28 | 255.255.255.240 | 14 | |
| /29 | 255.255.255.248 | 6 | |
| /30 | 255.255.255.252 | 2 | Point-to-point links |
| /31 | 255.255.255.254 | 2 (special) | RFC 3021 point-to-point |
| /32 | 255.255.255.255 | 1 | Single host |
Formula:
Usable hosts = 2^(32 - prefix) - 2
For /24: 2^(32-24) - 2 = 2^8 - 2 = 254
For /27: 2^(32-27) - 2 = 2^5 - 2 = 30
Subnetting a /24 network
You have 10.0.1.0/24 (254 usable hosts) and need to divide it into 4 equal subnets.
Step 1: Determine bits needed to create 4 subnets.
2^n ≥ 4 → n = 2 (borrow 2 bits from the host portion)
Step 2: New prefix length = 24 + 2 = /26
Step 3: Calculate the 4 subnets. Each /26 has a block size of 256/4 = 64:
| Subnet | Network | First usable | Last usable | Broadcast |
|---|---|---|---|---|
| 1 | 10.0.1.0/26 | 10.0.1.1 | 10.0.1.62 | 10.0.1.63 |
| 2 | 10.0.1.64/26 | 10.0.1.65 | 10.0.1.126 | 10.0.1.127 |
| 3 | 10.0.1.128/26 | 10.0.1.129 | 10.0.1.190 | 10.0.1.191 |
| 4 | 10.0.1.192/26 | 10.0.1.193 | 10.0.1.254 | 10.0.1.255 |
Each /26 has 62 usable hosts.
Subnetting for specific host requirements
Scenario: You need a subnet with at least 50 hosts.
2^n - 2 ≥ 50 → 2^6 - 2 = 62 → n = 6 host bits → prefix = 32 - 6 = /26
Scenario: You need a subnet with at least 100 hosts.
2^n - 2 ≥ 100 → 2^7 - 2 = 126 → n = 7 → prefix = /25
Scenario: Point-to-point link (exactly 2 hosts, one router interface on each end):
Use /30 for standard: 2 usable hosts. Or /31 (RFC 3021): treats both addresses as usable on point-to-point links — saves 2 addresses vs /30.
The subnet cheat sheet
Blocks that multiples of: 128 64 32 16 8 4 2 1
For any subnet, the block sizes follow powers of 2:
| Prefix | Subnet mask | Block size | Usable hosts | Networks in /24 |
|---|---|---|---|---|
| /25 | 255.255.255.128 | 128 | 126 | 2 |
| /26 | 255.255.255.192 | 64 | 62 | 4 |
| /27 | 255.255.255.224 | 32 | 30 | 8 |
| /28 | 255.255.255.240 | 16 | 14 | 16 |
| /29 | 255.255.255.248 | 8 | 6 | 32 |
| /30 | 255.255.255.252 | 4 | 2 | 64 |
Quick formula: The last octet of the broadcast address = network address’s last octet + block size - 1.
For 10.0.0.64/26 (block size 64): broadcast = 64 + 64 - 1 = 10.0.0.127
Cloud networking and VPCs
In AWS, Azure, and GCP, you create Virtual Private Clouds (VPCs) with CIDR blocks and divide them into subnets. Standard patterns:
AWS VPC example
VPC: 10.0.0.0/16 (65,534 usable IPs)
├── Public: 10.0.1.0/24 (254 IPs — internet-facing)
├── Private: 10.0.2.0/24 (254 IPs — app servers)
└── Database: 10.0.3.0/24 (254 IPs — RDS instances)
AWS reserves 5 IP addresses per subnet (not just 2): the network address, VPC router (.1), DNS (.2), reserved for future use (.3), and broadcast (.255). So a /24 has 251 usable IPs in AWS, not 254.
Multi-AZ pattern (3 availability zones)
VPC: 10.0.0.0/16
├── AZ-a public: 10.0.1.0/24
├── AZ-b public: 10.0.2.0/24
├── AZ-c public: 10.0.3.0/24
├── AZ-a private: 10.0.11.0/24
├── AZ-b private: 10.0.12.0/24
└── AZ-c private: 10.0.13.0/24
Matching subnet sizes across AZs makes scaling consistent. The /11 in the third octet for private subnets is a convention to visually separate public (single-digit) from private (double-digit) subnets.
IPv6 subnetting
IPv6 addresses are 128 bits, written as 8 groups of 4 hex digits: 2001:db8::/32.
A typical IPv6 allocation from an ISP is a /48. You can subnet it into /64 networks — each /64 has 2^64 ≈ 18 quintillion addresses. Standard practice: use /64 for every subnet (even if you only have 3 devices).
| IPv6 prefix | Subnets from /48 | Use |
|---|---|---|
| /48 | 1 | Typical ISP allocation |
| /56 | 256 /56s from /48 | Smaller site allocation |
| /64 | 65,536 /64s from /48 | Standard subnet size |
Using the Subnet Calculator
The Subnet Calculator takes any IP address + prefix length and returns:
- Network address
- Broadcast address
- Subnet mask (dotted decimal)
- First and last usable host addresses
- Total number of hosts
- CIDR notation
It also supports VLSM (Variable Length Subnet Masking) — dividing a block into subnets of different sizes based on specific host requirements.
Related tools
- Subnet Calculator — calculate subnets from CIDR notation
- HTTP Status Codes — HTTP response code reference
- User Agent Parser — parse browser/device information
Related posts
- Private IP Address Ranges, Subnets, and CIDR Notation Explained — The three RFC 1918 private ranges, what CIDR notation actually means, subnet mas…
- CIDR Notation Explained — What /24, /16, /8 Mean in IP Addresses — CIDR notation is the slash number after an IP address — /24, /16, /8. It specifi…
- DHCP IP Allocation — How Dynamic IP Assignment Works — DHCP (Dynamic Host Configuration Protocol) automatically assigns IP addresses, s…
Related tool
Calculate IPv4 subnets — network, broadcast, usable range, wildcard mask. Input CIDR (/24) or dotted mask (255.255.255.0). Binary visualization.
Written by Mian Ali Khalid. Part of the Dev Productivity pillar.