CIDR notation explained
An IPv4 address is a 32-bit number, written as four decimal octets for people to read. Classless Inter-Domain Routing
(CIDR) adds a prefix length after a slash. In 10.20.30.45/22 the first 22 bits identify the
network and the remaining 10 identify a host inside it.
Each extra prefix bit halves the block. Each bit removed doubles it. That single rule generates the whole table, and knowing a few entries by heart makes log review and firewall work much faster.
| Prefix | Subnet mask | Wildcard | Addresses | Usable |
|---|---|---|---|---|
| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,216 | 16,777,214 |
| /16 | 255.255.0.0 | 0.0.255.255 | 65,536 | 65,534 |
| /22 | 255.255.252.0 | 0.0.3.255 | 1,024 | 1,022 |
| /24 | 255.255.255.0 | 0.0.0.255 | 256 | 254 |
| /26 | 255.255.255.192 | 0.0.0.63 | 64 | 62 |
| /28 | 255.255.255.240 | 0.0.0.15 | 16 | 14 |
| /30 | 255.255.255.252 | 0.0.0.3 | 4 | 2 |
| /31 | 255.255.255.254 | 0.0.0.1 | 2 | 2 (RFC 3021) |
| /32 | 255.255.255.255 | 0.0.0.0 | 1 | 1 (host route) |
Binary subnetting made visual
The bit map above shows why a prefix that does not end on an octet boundary is hard to read in decimal. For
10.20.30.45/22 the boundary falls inside the third octet:
Address 00001010.00010100.000111|10.00101101 10.20.30.45
Mask 11111111.11111111.111111|00.00000000 255.255.252.0
Network 00001010.00010100.000111|00.00000000 10.20.28.0
Last 00001010.00010100.000111|11.11111111 10.20.31.255 - Write the address and the mask in binary.
- Keep every bit under a 1 in the mask and clear the rest. The result is the network address.
- Set all of the host bits to 1 instead. The result is the last address, which is the broadcast address.
- The addresses between them are usable by hosts.
A shortcut works in decimal. Subtract the interesting mask octet from 256 to get the block size: 256 − 252 = 4. Networks start at multiples of 4 in that octet (0, 4, 8, and so on). The largest multiple that does not exceed 30 is 28, so the network is 10.20.28.0 and the next one is 10.20.32.0.
A note for people who script this
JavaScript's bitwise operators return signed 32-bit integers, so masking an address of 128.0.0.0 or above can produce a negative number, and shifting by 32 does nothing at all. This calculator converts each result back to unsigned and is tested against arbitrary-precision arithmetic at every prefix from /0 to /32.
Cisco wildcard masks and subnet masks
A wildcard mask is what remains when each octet of the subnet mask is subtracted from 255. Cisco IOS uses it to say which bits of an address to ignore.
access-list 10 permit 10.20.28.0 0.0.3.255
router ospf 1
network 10.20.28.0 0.0.3.255 area 0 Mixing the two up is a security problem and not only a syntax error. If a subnet mask is typed where a wildcard is expected, the router accepts it and matches a completely different set of addresses. A rule meant for one network may permit addresses all over the internet. Platforms also differ: Cisco ASA access lists take subnet masks, and NX-OS accepts prefix notation.
Why /31 works on point-to-point links
A traditional /30 spends four addresses to connect two routers. One names the network and one is the broadcast address, so half of the block is overhead. A link with only two ends has no need for a broadcast address, because anything sent is for the other end.
RFC 3021 therefore states that on a point-to-point link with a 31-bit mask, the two addresses must be interpreted as host addresses. A network with 500 router links saves 1,000 addresses. It also removes the directed broadcast address, which has been abused to amplify denial-of-service traffic. Check that both devices and your monitoring tools support it.
The allocator uses a /30 for two hosts by default, which is safe on any kind of segment. Turn on the /31 option when your two-host entries really are point-to-point links.
A VLSM design, step by step
Variable Length Subnet Masking (VLSM) gives each subnet its own prefix, so a two-address link does not consume the same space
as an office floor. Suppose that a branch has 192.168.10.0/24 and needs these networks:
- List the needs. Servers 50, Staff 100, Management 10, WAN link 2. Count the gateway address as a host, and leave room for growth.
- Sort from the largest. Staff, Servers, Management, WAN.
- Choose the smallest block that fits each. 100 needs a /25, 50 needs a /26, 10 needs a /28 and 2 needs a /30.
- Place them one after another from the start of the parent block.
| Network | Subnet | Usable range | Utilization |
|---|---|---|---|
| Staff (100) | 192.168.10.0/25 | .1 to .126 | 79.4% |
| Servers (50) | 192.168.10.128/26 | .129 to .190 | 80.6% |
| Management (10) | 192.168.10.192/28 | .193 to .206 | 71.4% |
| WAN link (2) | 192.168.10.208/30 | .209 to .210 | 100.0% |
The plan uses 212 of 256 addresses. The 44 that remain are 192.168.10.212/30,
192.168.10.216/29 and 192.168.10.224/27. Adding a 60-host lab would need another 64, which the
allocator reports as an overflow along with the parent size that would fit. High utilization is efficient today but
leaves little room to grow, so treat anything above about 80% as a prompt to consider the next size up.
Scopes that matter in security work
The scope field names the special-purpose range that contains the address. RFC 1918 private ranges should never appear as a
source on the internet. 100.64.0.0/10 is carrier-grade NAT space, which is shared by many subscribers and is a
poor choice for a block rule. Link-local 169.254.0.0/16 often means that DHCP failed, and it also contains
169.254.169.254, the cloud metadata address that server-side request forgery attacks target. A large block can
cover several scopes. 172.0.0.0/8 is mostly public even though part of it is private, and the calculator warns you
when that happens.
Can I use a /31 on an ordinary LAN?
No. RFC 3021 is for point-to-point links that connect exactly two devices. A /31 has no broadcast address and no room for a third device, so use a /30 or larger on a shared segment. Both ends of the link must also support /31, which most current routers and firewalls do.
Why does VLSM allocate the largest subnet first?
Every block must start at a multiple of its own size. Placing large blocks first keeps the next free address aligned for every smaller block that follows, so no gaps appear. Allocating small blocks first can leave fragments that are too small or misaligned for a large subnet, even when enough total addresses remain.