CIDR and Subnetting Explained, With a Cheat Sheet
What /24 really means: work out network ranges, masks and usable hosts, learn the private ranges, and plan cloud subnets, with a cheat sheet.
You'll meet CIDR notation everywhere in modern infrastructure: 10.0.0.0/16 for a cloud network, 192.168.1.0/24 on a home router, 0.0.0.0/0 in a firewall rule, 172.17.0.0/16 for Docker. The slash and the number after it pack a lot of information into a few characters, and getting one wrong can expose a database or break a deployment.
This guide explains what the prefix means, how to work out a network's range by hand, which ranges are private, and how to plan subnets for a cloud network, with a cheat sheet you can keep.
IP addresses are just numbers
An IPv4 address such as 192.168.10.42 is a 32-bit number, written as four 8-bit parts (octets) in decimal:
192 .168 .10 .42
11000000 .10101000 .00001010 .00101010
A network is a block of consecutive addresses that share the same leading bits. CIDR (Classless Inter-Domain Routing) writes that block as the first address plus the number of shared bits.
What the /24 means
The number after the slash is the prefix length: how many leading bits are fixed for the whole network. The remaining bits identify individual addresses inside it.
192.168.10.0/24
└───┬────┘ ↑
│ └ the last 8 bits vary: 256 addresses
└ the first 24 bits are fixed
So:
- /24 fixes 24 bits and leaves 8, so it has 2⁸ = 256 addresses:
192.168.10.0to192.168.10.255. - /16 leaves 16 bits: 65,536 addresses.
- /32 fixes every bit: exactly one address.
- /0 fixes nothing: every IPv4 address. That's why
0.0.0.0/0in a firewall rule means "anyone on the internet".
Each step of one in the prefix halves or doubles the network. A /25 is half a /24; a /23 is two /24s.
The subnet mask is the same idea
Older tools write the prefix as a subnet mask: the prefix's bits set to 1, the rest 0, written like an address.
/24 → 11111111.11111111.11111111.00000000 → 255.255.255.0
/26 → 11111111.11111111.11111111.11000000 → 255.255.255.192
192.168.10.0/24 and "192.168.10.0, mask 255.255.255.0" mean exactly the same thing. A valid mask is always a run of 1s followed by a run of 0s; something like 255.0.255.0 isn't a mask.
Working out a network by hand
Take 192.168.10.42/26. A /26 leaves 6 bits for hosts, so the network has 2⁶ = 64 addresses. Networks always start at a multiple of their size, so in the last octet the /26 blocks are 0–63, 64–127, 128–191 and 192–255. 42 falls in the first block.
| Value | |
|---|---|
| Network address | 192.168.10.0 |
| Subnet mask | 255.255.255.192 |
| Broadcast address | 192.168.10.63 |
| Usable hosts | 192.168.10.1 to 192.168.10.62 (62 hosts) |
Two addresses in a classic IPv4 subnet aren't usable by hosts:
- the network address, the first one, which names the network itself;
- the broadcast address, the last one, which reaches every host on it.
That's why a /24 has 254 usable hosts, not 256.
In binary, the network address is the IP AND the mask, and the broadcast address is the network OR the inverted mask. In JavaScript (>>> 0 keeps the result unsigned):
const toInt = (ip) => ip.split('.').reduce((n, part) => n * 256 + Number(part), 0);
const toIp = (n) => [24, 16, 8, 0].map((shift) => (n >>> shift) & 255).join('.');
function subnet(cidr) {
const [ip, bits] = cidr.split('/');
const mask = bits === '0' ? 0 : (~0 << (32 - Number(bits))) >>> 0;
const network = (toInt(ip) & mask) >>> 0;
const broadcast = (network | ~mask) >>> 0;
return { network: toIp(network), mask: toIp(mask), broadcast: toIp(broadcast) };
}
subnet('192.168.10.42/26'); // { network: '192.168.10.0', mask: '255.255.255.192', broadcast: '192.168.10.63' }
Python's standard library does all of it for you:
import ipaddress
net = ipaddress.ip_network("192.168.10.0/26")
net.netmask # IPv4Address('255.255.255.192')
net.broadcast_address # IPv4Address('192.168.10.63')
net.num_addresses # 64
ipaddress.ip_address("192.168.10.70") in net # False: it's in the next /26
list(net.subnets(new_prefix=28)) # four /28s
Or skip the maths: type 192.168.10.42/26 into the subnet calculator and it shows the range, mask, broadcast, host count and address type, checks whether another address belongs, and splits the network into smaller ones.
Cheat sheet: common prefix lengths
| Prefix | Subnet mask | Addresses | Usable hosts | Typical use |
|---|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 | The whole 10.0.0.0 private range |
| /16 | 255.255.0.0 | 65,536 | 65,534 | A cloud VPC, a Docker network |
| /20 | 255.255.240.0 | 4,096 | 4,094 | A large subnet (AWS default-VPC subnets) |
| /22 | 255.255.252.0 | 1,024 | 1,022 | A big office floor |
| /24 | 255.255.255.0 | 256 | 254 | A home or small office LAN, a typical subnet |
| /26 | 255.255.255.192 | 64 | 62 | A small app tier |
| /28 | 255.255.255.240 | 16 | 14 | A tiny subnet (AWS's minimum) |
| /30 | 255.255.255.252 | 4 | 2 | An old-style point-to-point link |
| /31 | 255.255.255.254 | 2 | 2 | A point-to-point link (RFC 3021) |
| /32 | 255.255.255.255 | 1 | 1 | A single host, in routes and firewall rules |
/31 and /32 are special. A /31 has no room for network and broadcast addresses, so RFC 3021 lets both addresses be used on a point-to-point link. A /32 is one address: the way you allow a single IP in a firewall or security group.
Private and special ranges
Some ranges never route on the public internet, and are free to use inside your own networks:
| Range | What it is |
|---|---|
10.0.0.0/8 | Private (RFC 1918): the largest, popular for cloud and corporate networks |
172.16.0.0/12 | Private (RFC 1918): 172.16.0.0 to 172.31.255.255, not all of 172.x |
192.168.0.0/16 | Private (RFC 1918): home and small office routers |
100.64.0.0/10 | Shared address space for carrier-grade NAT (RFC 6598), also used by some VPNs |
127.0.0.0/8 | Loopback: your own machine |
169.254.0.0/16 | Link-local: what a device gives itself when DHCP fails; cloud metadata services live here too |
192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24 | Reserved for documentation and examples (RFC 5737) |
A common slip: 172.32.0.0 is not private. The private block ends at 172.31.255.255.
Planning subnets for a cloud network
Cloud networks are where CIDR mistakes cost the most, because changing a network's range later usually means rebuilding it.
- Pick a private range that won't clash. If the network will ever connect to an office, a VPN or another cloud network (peering), their ranges must not overlap. Avoid
192.168.0.0/24and192.168.1.0/24, which half the world's home routers use. - Size it generously. A /16 for a VPC gives room to grow. Addresses inside a private range cost nothing.
- Split it into subnets per tier and zone. For example, split
10.0.0.0/16into four /18s, one per availability zone and tier group:10.0.0.0/18,10.0.64.0/18,10.0.128.0/18and10.0.192.0/18. - Remember the cloud's reserved addresses. AWS and Azure reserve 5 addresses in every subnet (the first four and the last one), and Google Cloud reserves 4. A /28 on AWS leaves 11 usable addresses, not 14.
- Leave space for containers. Kubernetes can hand an IP to every pod, which uses up addresses far faster than one per server.
The subnet calculator's "Split into" option lists the smaller networks for you, so you can paste them straight into your infrastructure code.
A quick look at IPv6
IPv6 addresses are 128 bits, written as eight groups of four hex digits, with the longest run of zero groups shortened to ::. CIDR works exactly the same way, but the numbers are on another scale:
- /64 is the standard size for a single subnet, and it's what automatic address configuration (SLAAC) expects. One /64 holds 2⁶⁴ addresses, about 18 quintillion.
- /56 or /48 is what an ISP or a cloud typically gives a home or a site, leaving room for 256 or 65,536 subnets of /64.
- There's no broadcast address in IPv6, so the "minus two" rule doesn't apply.
2001:db8::/32is reserved for documentation, like the IPv4 example ranges above.
The calculator handles IPv6 too, including the shortest standard form of each address (RFC 5952).
Mistakes to avoid
- Opening
0.0.0.0/0by accident. In a firewall or security group, it means the entire internet. Use/32for one address. - Overlapping ranges between networks you'll later connect. Plan the whole address space up front.
- Forgetting reserved addresses, both the network and broadcast addresses and your cloud's own.
- Starting a network on the wrong boundary.
192.168.10.42/26is a host inside192.168.10.0/26; many tools will reject the first, or silently use the second. - Assuming all of 172.x is private. Only
172.16.0.0/12is.
Summary
- The number after the slash is how many leading bits the network fixes. Every step halves or doubles the network.
- Addresses = 2^(32 − prefix). Usable hosts are two fewer, except on /31 and /32.
- Private ranges are
10.0.0.0/8,172.16.0.0/12and192.168.0.0/16. - Plan cloud networks generously, without overlaps, and remember the provider's reserved addresses.
Keep the subnet calculator handy for the next security group, VPC or router you set up.