📊 CIDR Calculator
Convert between CIDR notation and subnet masks to better understand network ranges and IP addressing.
From a prefix to a mask
A prefix is just an instruction to build a 32-bit mask by shifting a full row of 1 bits left, so the low bits fall away and become the host part:
mask = 0xFFFFFFFF << (32 - prefix)
network = ip AND mask
broadcast = network OR (NOT mask)
addresses = 2^(32 - prefix)
Enter 10.20.30.44/27. Shifting left by 5 leaves 0xFFFFFFE0, which is 255.255.255.224. In the last octet 44 is 00101100 and 224 is 11100000, so the network is 10.20.30.32; NOT 224 is 31, and 32 OR 31 is 63, so the broadcast is 10.20.30.63. Five host bits give 32 addresses and 30 usable ones, .33 to .62.
Aggregating blocks into one prefix
Blocks only merge when they are adjacent and the shorter prefix lands on its own boundary. Four consecutive /24s, 192.168.4.0 through 192.168.7.0, collapse into 192.168.4.0/22: the /22 mask is 255.255.252.0, and 4, 5, 6 and 7 all AND with 252 to give 4, so all four share one network address.
- 192.168.0.0/24 and 192.168.1.0/24 aggregate to 192.168.0.0/23.
- 192.168.1.0/24 and 192.168.2.0/24 do not. Under the /23 mask 255.255.254.0, 1 ANDs to 0 and 2 ANDs to 2 - they sit in different /23s.
- Every bit you drop from the prefix doubles the block, so merging n prefixes needs n to be a power of two and the first one to be aligned to n.
Frequently asked questions
What is /27 as a subnet mask?
255.255.255.224. Twenty-seven 1 bits fill three octets plus the top three of the fourth, and 11100000 is 224. The block holds 32 addresses, 30 of them usable.
How many IP addresses are in a /22?
1,024 addresses, of which 1,022 are usable hosts. A /22 has 10 host bits, and 2^10 is 1,024 - the same as four /24 blocks side by side.
Can any two subnets be combined into one CIDR block?
No. They must be the same size, next to each other, and the lower one must start on a boundary of the combined size. 10.0.2.0/24 and 10.0.3.0/24 merge into 10.0.2.0/23; 10.0.3.0/24 and 10.0.4.0/24 cannot.