CIDR Notation: What the Slash Means
Decode the slash in addresses like 192.168.1.0/24, work out block sizes and see why routers and firewalls rely on it.
Key takeaways
- The slash number is the prefix length: the count of leading bits shared by every address in the block.
- An IPv4 block holds 2 to the power of (32 minus the prefix length) addresses.
- Each step up in the prefix length halves the block, and each step down doubles it.
- A block must start on a multiple of its own size, or the notation describes a different range than you intended.
The number after the slash says how many bits, counted from the left, are fixed for every address in the block. In 192.168.1.0/24, the first 24 bits stay the same and the remaining 8 can vary, so the block holds 256 addresses from 192.168.1.0 to 192.168.1.255.
A bigger number after the slash means a smaller block. That feels backward until you remember that the number counts what is locked down, and more locked bits leave fewer free ones.
Reading the notation
CIDR stands for Classless Inter-Domain Routing, described today in RFC 4632. The notation has two parts: an address and a prefix length.
For IPv4 the prefix length runs from 0 to 32. /32 fixes every bit and names a single address. /0 fixes nothing and matches every address, which is why 0.0.0.0/0 is used to mean "anywhere" and serves as the default route.
Doing the arithmetic
Subtract the prefix length from 32 to get the number of free bits, then raise 2 to that power. A /22 has 10 free bits, so it holds 1,024 addresses.
| Prefix | Equivalent mask | Addresses | Common use |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,216 | Very large allocations |
| /16 | 255.255.0.0 | 65,536 | A site or cloud network |
| /22 | 255.255.252.0 | 1,024 | A busy LAN or small provider block |
| /24 | 255.255.255.0 | 256 | A typical LAN |
| /27 | 255.255.255.224 | 32 | A small segment |
| /30 | 255.255.255.252 | 4 | A traditional router-to-router link |
| /32 | 255.255.255.255 | 1 | One specific host |
On a normal subnet, two of those addresses are reserved for the network and broadcast, so a /24 offers 254 usable host addresses. In a route or firewall rule, the block is just a range and all addresses count.
The mask column is the older way of writing the same thing. Subnet masks and how to calculate them shows how to convert between them.
Why classes went away
Early IPv4 sorted addresses into classes based on their first bits. A class A network was what we would now call a /8, class B a /16, and class C a /24. An organization needing 2,000 addresses had no good fit: one class C was far too small and a class B was far too large.
That wasted address space. Handing out many small networks instead also bloated routing tables, since each needed its own entry. CIDR, adopted in the early 1990s, let a block be any power-of-two size and let adjacent blocks be advertised as a single route. The shortage did not end, as the IPv4 address shortage explains, but allocation became far more efficient.
You still hear "class C" used loosely for a /24. It is harmless in conversation and misleading in a configuration discussion, because the class tells you nothing about the mask a modern network actually uses.
Alignment: blocks start in fixed places
A CIDR block must begin at a multiple of its size. A /26 holds 64 addresses, so it can start at .0, .64, .128 or .192 in the last octet, and nowhere else.
If you write 203.0.113.70/26, the first 26 bits still define the block, so the block is 203.0.113.64/26 and .70 is simply a host inside it. Both forms are useful:
- On an interface,
203.0.113.70/26means "my address is .70 and my subnet has a 26-bit prefix". - In a route or rule, you should write the block's true start,
203.0.113.64/26. Some tools silently correct the other form, and others reject it.
You also cannot describe an arbitrary range with one block. The range from .10 to .20 does not start or end on suitable boundaries, so it takes several blocks:
203.0.113.10/31 (.10 - .11)
203.0.113.12/30 (.12 - .15)
203.0.113.16/30 (.16 - .19)
203.0.113.20/32 (.20) The range to CIDR tool does this decomposition for you, which is handy when someone sends a list of first and last addresses and your firewall wants prefixes.
Halving and doubling
A useful mental picture is a tree. Every block splits into exactly two blocks with a prefix one longer.
Going the other way, two neighboring blocks of the same size can merge into one with a prefix one shorter, but only if they are the two halves of the same parent. 203.0.113.0/26 and 203.0.113.64/26 merge into 203.0.113.0/25. The pair .64/26 and .128/26 does not, even though they touch.
Combining many blocks this way is route summarization.
Where you meet the slash
Routing tables. Every route is a prefix and a next hop. When several prefixes match a destination, the router uses the longest one, meaning the most specific. A /24 route beats a /16 route covering the same address. This rule is central to how routers decide where to send a packet.
Firewall and cloud security rules. 192.0.2.50/32 allows one machine. 192.0.2.0/24 allows its whole neighborhood. 0.0.0.0/0 allows the entire IPv4 internet, which deserves a second look every time you type it.
Allow lists in services. Many dashboards ask for a CIDR range of office addresses. Use /32 if you have one public address.
VPN configuration. The list of prefixes sent through a tunnel decides which traffic uses it.
Testing whether an address is in a block
Suppose a rule allows 198.51.100.96/27 and you see a connection from 198.51.100.130. Is it covered? A /27 holds 32 addresses, so the block runs from .96 to .127. Address .130 falls in the next block, starting at .128, so the rule does not match it.
The same method works when the boundary is in the third octet. A /21 leaves 11 free bits, or 2,048 addresses, which is 8 values of the third octet. So 10.4.16.0/21 runs from 10.4.16.0 to 10.4.23.255. The address 10.4.22.9 is inside and 10.4.24.9 is outside.
When many ranges are involved, a range matcher can test an address against them faster and with fewer slips than doing it by eye.
Choosing a prefix length
When you are the one picking, start from what the block has to hold and leave headroom.
- A single server or office public address:
/32. - A router link:
/31where both ends support it, otherwise/30. - A small segment such as management interfaces:
/28or/27. - An ordinary user LAN:
/24, because the arithmetic is easy and 254 hosts is ample for most offices. - A container for a whole site:
/16to/20, split into smaller blocks as needed.
Very large single subnets are legal but have a cost. Every broadcast reaches every member, and a fault such as a loop affects all of them. Splitting into several /24 blocks with routing between them usually behaves better. On public addresses, the pressure runs the other way: they are scarce and often charged for, so you request the smallest block that fits.
For public space, remember that the prefix you receive from a provider limits what you can do with it. A /29 gives eight addresses, and after the network, broadcast and the provider's gateway, only five remain for your equipment.
CIDR in IPv6
IPv6 uses the same notation with 128 bits. 2001:db8::/32 fixes the first 32 bits. A single LAN is normally a /64, one address is a /128 and the default route is ::/0. Because the numbers are so large, people think in subnets instead of host counts, as IPv6 subnetting describes.
An IPv6 firewall rule needs IPv6 prefixes. Allowing 0.0.0.0/0 does nothing for IPv6 traffic, and the reverse is true of ::/0.
Mistakes to watch for
- Typing /24 when you mean one host.
192.0.2.50/24in an allow rule may admit all 256 addresses. Use/32for one. - Reading the number as a size.
/30is tiny,/8is enormous. - Assuming every address ending in .0 starts a block.
10.0.1.0is an ordinary host inside10.0.0.0/23. - Overlapping entries. A
/24and a/25inside it can coexist in a routing table, where the longer one wins. In a first-match firewall list, order decides instead. - Widening a block to include a stray address. Moving from
/28to/20to cover one extra host admits thousands of others. Add a second narrow rule.
Reading a list of prefixes
Configuration files and provider documentation often give long lists of CIDR blocks. Read them in two passes. First look at the prefix lengths to get a sense of scale: a /12 in an allow list is about a million addresses, while a /29 is eight. Then look for overlaps, where a shorter prefix already contains a longer one. The longer entry is then redundant in an allow list, although it may still matter in a routing table where it sends traffic a different way.
Keep a comment next to each entry saying who it belongs to and why it is there. Address blocks change owners, and a rule nobody can explain tends to stay forever.
Review such lists on a schedule, and remove any entry that no longer has an owner who can vouch for it. A short list that people understand is safer than a long one they are afraid to touch.
Common questions
Is /24 better than /16?
Neither is better. A /24 is a manageable size for one segment. A /16 is usually a container that you split into many segments.
Why do I see /31 on router links?
RFC 3021 allows a two-address subnet on a point-to-point link, with no separate network or broadcast address. It saves half the addresses compared with a /30.
How do I check whether an address is inside a block?
Apply the prefix length to both the address and the block's start, and compare the fixed bits. In practice, work out the block's first and last address and see whether yours falls between them, or let a range matching tool do it.