CIDR Explained
CIDR (Classless Inter-Domain Routing), defined in RFC 4632, is the notation system that replaced rigid classful addressing in 1993. Instead of being forced into /8, /16, or /24 blocks (classes A, B, and C), CIDR lets you write any prefix length from /0 to /32. This flexibility is what makes modern subnetting, route aggregation, and VLSM possible. Use the CIDR calculator to convert between prefixes and masks interactively.
The CIDR format
A CIDR block is written as address/prefix, where the prefix is the number of leading bits that form the network portion. For example, 10.0.0.0/8 means the first 8 bits are the network and the remaining 24 bits are host addresses.
10.0.0.0/8 → network bits: 8, host bits: 24
172.16.0.0/12 → network bits: 12, host bits: 20
192.168.1.0/24 → network bits: 24, host bits: 8
203.0.113.0/28 → network bits: 28, host bits: 4From classful to classless
Before CIDR, the first octet determined the class and therefore the mask. A network starting with 192 had to be a /24, whether you needed 254 hosts or 10. This wasted enormous numbers of addresses. CIDR decoupled the mask from the address, so the same 192.0.2.0 block can be a /28 (14 hosts) or a /23 (510 hosts) as needed.
| Class | Leading bits | Default prefix | Range (first octet) |
|---|---|---|---|
| A | 0 | /8 | 1–126 |
| B | 10 | /16 | 128–191 |
| C | 110 | /24 | 192–223 |
| D (multicast) | 1110 | n/a | 224–239 |
| E (reserved) | 1111 | n/a | 240–255 |
These classes are now historical. Modern routers and operating systems ignore them and use only the explicit prefix.
Converting a prefix to a dotted-decimal mask
The prefix is the count of 1-bits. Split it into octets: the first prefix ÷ 8 octets are 255, the next octet is a partial value, and the rest are 0.
| Bits in octet | Value |
|---|---|
| 0 | 0 |
| 1 | 128 |
| 2 | 192 |
| 3 | 224 |
| 4 | 240 |
| 5 | 248 |
| 6 | 252 |
| 7 | 254 |
| 8 | 255 |
For /28: 28 ÷ 8 = 3 full octets (255.255.255) plus 4 bits. Four bits = 240, so the mask is 255.255.255.240.
Host capacity by prefix
| Prefix | Mask | Total addresses | Usable hosts |
|---|---|---|---|
| /30 | 255.255.255.252 | 4 | 2 |
| /29 | 255.255.255.248 | 8 | 6 |
| /28 | 255.255.255.240 | 16 | 14 |
| /27 | 255.255.255.224 | 32 | 30 |
| /26 | 255.255.255.192 | 64 | 62 |
| /25 | 255.255.255.128 | 128 | 126 |
| /24 | 255.255.255.0 | 256 | 254 |
| /23 | 255.255.254.0 | 512 | 510 |
| /22 | 255.255.252.0 | 1024 | 1022 |
The formula is 2^(32 − prefix) − 2. See the CIDR cheat sheet for the full table from /0 to /32.
Real-world usage
Routing tables
# A single /22 summary replaces four /24s
192.168.0.0/22 via 10.0.0.1
# Instead of:
192.168.0.0/24 via 10.0.0.1
192.168.1.0/24 via 10.0.0.1
192.168.2.0/24 via 10.0.0.1
192.168.3.0/24 via 10.0.0.1Firewall rules (iptables)
iptables -A INPUT -s 10.50.0.0/16 -j ACCEPT
iptables -A INPUT -s 198.51.100.0/24 -p tcp --dport 443 -j ACCEPTCloud security groups
# Allow internal management subnet only
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["10.20.30.0/26"]
}CIDR vs wildcard masks
CIDR prefixes and subnet masks use contiguous 1-bits for the network. Cisco ACLs and OSPF use wildcard masks, which are the bitwise inverse — 0-bits match and 1-bits ignore. A /24 (255.255.255.0) becomes wildcard 0.0.0.255. See Wildcard Masks Explained for the full conversion method and the wildcard mask calculator.
Related guides & tools
- IPv4 Subnetting Guide — the complete walkthrough
- Subnetting Cheat Sheet — full prefix table
- Route Summarization Explained — building supernets
- Route Summarization Calculator — calculate summary routes
- RFC 1918 Private IP Address Ranges