Subnetting and CIDR Explained with Simple Examples
Subnetting looks like arithmetic on binary numbers, but a handful of facts and one trick cover almost everything you'll meet in practice.
IP address, mask, prefix
An IPv4 address has 32 bits, written as four bytes: 192.168.10.77. A subnet mask says which part is the network and which is the host:
192.168.10.77 / 24 (CIDR notation)
= address 192.168.10.77, mask 255.255.255.0
/24 means the first 24 bits are the network. The remaining 32 - 24 = 8 bits identify hosts inside it.
The cheat table
| CIDR | Subnet mask | Addresses | Usable hosts |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 |
| /16 | 255.255.0.0 | 65,536 | 65,534 |
| /20 | 255.255.240.0 | 4,096 | 4,094 |
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 |
| /31 | 255.255.255.254 | 2 | 2 (point-to-point links) |
| /32 | 255.255.255.255 | 1 | a single host |
Formulas:
- Addresses =
2^(32 - prefix) - Usable hosts = addresses
- 2. One address is the network address (all host bits 0) and one is the broadcast (all host bits 1).
The fast method: block size
For prefixes between /24 and /32, only the last octet matters. Find the block size = 256 - mask value in that octet.
Example: which network is 192.168.10.77/26 in?
/26→ mask255.255.255.192→ block size256 - 192 = 64.- Networks start at multiples of 64 in the last octet:
.0,.64,.128,.192. 77lies between 64 and 127, so the network is 192.168.10.64/26.- Broadcast = next network − 1 = 192.168.10.127.
- Usable hosts: .65 to .126 (62 addresses).
Splitting a network
To split 10.0.0.0/24 into four equal subnets, borrow 2 bits (4 = 2²), so the new prefix is /26:
| Subnet | Range | Usable hosts | Broadcast |
|---|---|---|---|
| 10.0.0.0/26 | .1 - .62 | 62 | .63 |
| 10.0.0.64/26 | .65 - .126 | 62 | .127 |
| 10.0.0.128/26 | .129 - .190 | 62 | .191 |
| 10.0.0.192/26 | .193 - .254 | 62 | .255 |
To size a subnet: take the number of hosts you need, add 2, and round up to the next power of two. For 50 hosts: 52 → 64 → /26. For 100 hosts: 102 → 128 → /25.
Private and special ranges
| Range | Use |
|---|---|
10.0.0.0/8 |
Private (RFC 1918) |
172.16.0.0/12 (172.16.0.0 to 172.31.255.255) |
Private |
192.168.0.0/16 |
Private, typical home networks |
100.64.0.0/10 |
Carrier-grade NAT, also used by Tailscale |
169.254.0.0/16 |
Link-local. Seeing this on a PC means DHCP failed |
127.0.0.0/8 |
Loopback (localhost) |
Private addresses aren't routed on the internet and need NAT to go out.
Check it with a tool
sudo apt install -y ipcalc
ipcalc 192.168.10.77/26
Or with Python, which is already installed on most systems:
python3 -c "import ipaddress as i; n=i.ip_network('192.168.10.77/26', strict=False); print(n, n.netmask, n.broadcast_address, n.num_addresses-2)"
Mistakes to avoid
- Overlapping subnets. Two networks that overlap (for example a VPN using
192.168.1.0/24while your home LAN is also192.168.1.0/24) cause traffic to go to the wrong place. Pick unusual ranges for VPNs, such as10.8.0.0/24. - Forgetting the 2 reserved addresses. A
/29has 6 usable hosts, not 8. - Mixing up mask and wildcard. Cisco ACLs use wildcard masks, which are inverted (
0.0.0.255for a /24). - Planning too tight. Leave room to grow; renumbering is painful.
IPv6 in one paragraph
IPv6 addresses are 128 bits. The standard subnet for a LAN is a /64, and you don't count hosts, because every /64 holds 2⁶⁴ addresses. Providers usually hand out a /56 or /48 so you can create many /64s.