Start with "Why 254, Not 256"
A /24 is usually described as "254 usable hosts", not 256, and the reason is binary. IPv4 is 32 bits; /24 fixes the first 24 as the network number, leaving 8 host bits. Eight bits give 256 combinations (0–255), but two must be reserved:
all-zero host bits → network address (identifies the subnet)
all-one host bits → broadcast address (sent to every host)
Remove those two and 256 − 2 = 254 usable hosts. The rule 2^(32−prefix) − 2 holds at any prefix and underpins every calculation below.
Two Notations: Mask vs Prefix
| CIDR | Mask | Network bits | Usable hosts |
|---|---|---|---|
| /30 | 255.255.255.252 | 30 | 2 |
| /29 | 255.255.255.248 | 29 | 6 |
| /28 | 255.255.255.240 | 28 | 14 |
| /24 | 255.255.255.0 | 24 | 254 |
| /23 | 255.255.254.0 | 23 | 510 |
| /16 | 255.255.0.0 | 16 | 65,534 |
| /8 | 255.0.0.0 | 8 | 16,777,214 |
Convert the mask to binary and count the ones to get the prefix. See /16 and you know there are 16 host bits with 65,534 usable; see /30 and you know it is a point-to-point link.
Three Calculations You Must Master
1. Network Address (AND)
IP 11000000.10101000.00000101.00100101 (192.168.5.37)
mask /26 11111111.11111111.11111111.11000000 (255.255.255.192)
──────────────────────────────────────────────
AND 11000000.10101000.00000101.00000000 → 192.168.5.0
Clearing the host bits yields the network address.
2. Broadcast Address (Network OR All-One Host Bits)
In the same subnet, set every host bit to 1:
192.168.5.0 + (63) → 192.168.5.63
At a non-byte boundary, the key is "stride = 256 − last decimal octet of the mask". A mask of 255.255.255.192 gives stride 64, so the subnet spans 192.168.5.0–.63 with usable hosts .1–.62.
3. Usable Host Count
2^(32−prefix) − 2: /24 → 254; /26 → 62; /30 → 2.
Network = IP AND mask; broadcast = network OR all-one host bits; usable = 2^(host bits) − 2.
Cloud Architecture Advice
- Start a VPC with /16: leave room for multiple environments (dev/staging/prod) and subnets;
- /24 per environment: 254 hosts is plenty to start, easy to remember and manage;
- /30 for point-to-point (VPN/links): wastes only 2 addresses and barely occupies a range;
- Watch reserved addresses: cloud vendors usually reserve the first four and the last of each subnet (gateway, DNS, NAT, spare); account for them per their docs;
- Avoid /28 or smaller: they exhaust quickly and are hard to expand.
Reproducible Results
The mask, total addresses, usable hosts and broadcast of a /26, in one stdlib call, matching the IPv4 subnet calculator:
import ipaddress
net = ipaddress.ip_network('192.168.1.0/26')
print(net.netmask) # → 255.255.255.192
print(net.num_addresses) # → 64 (total addresses)
print(net.num_addresses - 2) # → 62 (usable: minus network and broadcast)
print(net.broadcast_address) # → 192.168.1.63
print(net[1], net[-2]) # → 192.168.1.1 192.168.1.62 (first/last usable)
Each +2 of prefix halves the host bits: /25=128, /26=64, /27=32. Remember usable = 2^(32−prefix) − 2 and you can drop the calculator.