CIDR Calculator – IP Range to CIDR
Convert an IPv4 CIDR block such as 10.0.0.0/22 into its address range, netmask and host count, convert a first–last IP range into the minimal set of CIDR blocks, or aggregate a list of blocks into one summarized list.
Convert Between IP Ranges and CIDR Blocks
CIDR Formula
Where:
- \(p\) — the prefix length, i.e. the number of leading bits the block fixes (0–32)
- \(N\) — total number of addresses covered by the block
- \(\text{IP}\) — the address you enter; the bitwise AND (
&) clears the host bits - \(\text{network}\) and \(\text{broadcast}\) — the first and last addresses of the block
A CIDR block is defined only by its prefix length: a /\(p\) block contains \(2^{32-p}\) addresses, starts at an address whose last \(32-p\) bits are zero, and its netmask has exactly \(p\) one-bits followed by zeros. The wildcard mask is simply the bitwise inverse of the netmask.
CIDR – Calculation Example
Example: convert the block 10.0.0.0/22 into its address range, the calculator's default value.
\[ N = 2^{32-22} = 2^{10} = 1024 \]
\[ \text{netmask} = 255.255.252.0 \quad \Rightarrow \quad \text{wildcard} = 0.0.3.255 \]
\[ \text{broadcast} = 10.0.0.0 + 1023 = 10.0.3.255 \]
Result: the block 10.0.0.0/22 covers the range 10.0.0.0 – 10.0.3.255 — 1,024 addresses in total, of which 1,022 are usable for hosts (the network and broadcast addresses are reserved).
How to Use the Calculator
- Choose a Mode: "CIDR → address range", "Address range → CIDR blocks", or "Aggregate a list of CIDRs". Only the inputs used by the selected mode are shown.
- In CIDR → address range mode, enter a CIDR block such as
10.0.0.0/22. A bare address like192.168.1.1is treated as a /32 (a single host). The results show the first address (network), last address (broadcast), total addresses, netmask, wildcard mask, and the canonical block. - In Address range → CIDR blocks mode, enter the First IP address and Last IP address of the range (both inclusive). The calculator returns the minimal number of CIDR blocks that cover the range exactly, with no gaps or overlaps, plus a per-block breakdown.
- In Aggregate a list of CIDRs mode, paste your blocks into the CIDR blocks field — one per line, though commas and semicolons also work. Overlapping and adjacent blocks are merged automatically, and the whole list is summarized as the smallest exact set of blocks.
- Check Calculation details under the results for the step-by-step logic, including a note when an entered address had host bits set. For planning subnets around one block, the IP subnet calculator covers the same operations from a subnetting angle.
What Is CIDR?
Classless Inter-Domain Routing (CIDR) replaced the old class A/B/C system with a flexible notation that writes an address and its prefix length together: a.b.c.d/p. The prefix \(p\) says how many leading bits are common to every address in the block; the remaining \(32-p\) bits vary freely, so the block contains \(2^{32-p}\) addresses. That single rule explains everything else: a /24 has \(2^8 = 256\) addresses and netmask 255.255.255.0, a /22 has \(2^{10} = 1024\) addresses and netmask 255.255.252.0, and a /32 is one exact address.
A key consequence of the bit structure is alignment: a block of \(2^k\) addresses can only start at an address that is a multiple of \(2^k\). This is why, for example, 192.168.1.16/28 is valid (16 addresses starting at a multiple of 16) but 192.168.1.8/28 is not a proper block boundary. When you convert an arbitrary first–last range to CIDR, the range rarely lines up with a single block, so it must be split. The calculator uses a greedy algorithm: at each step it takes the largest block that both fits in the remaining addresses and is correctly aligned, which provably yields the minimum possible number of blocks.
Interpreting the numbers matters in practice. "Total addresses" is the raw size of the block, but classic subnetting (prefixes /0 through /30) reserves the first address as the network identifier and the last as the broadcast address, leaving two fewer usable for hosts. A /31 (per RFC 3021, for point-to-point links) and a /32 (a single host) are exceptions where every address is usable. If your goal is to plan how a larger block divides into smaller subnets with hosts per subnet, use the subnet calculator; to verify address arithmetic by hand, the binary converter shows the bit patterns behind the masks.
Tips and Limitations
- The calculator handles IPv4 only (four octets, 0–255, prefix /0–/32). IPv6 addresses are rejected.
- If you enter an address with host bits set, such as
10.0.1.7/22, the results describe the containing block (10.0.0.0/22), and the calculation details flag this. To be explicit, always enter the network address. - A first–last range is converted to the minimal exact set of blocks — coverage with no gaps and no duplicates. This is usually what routing tables and access-control lists want.
- Aggregation merges blocks only when they overlap or are directly adjacent; a gap of even one address keeps them separate.
- Very large results (e.g. aggregating many scattered /32s) can run to thousands of blocks; the table shows the first 200 and reports the full count.
Common CIDR Prefixes Reference
| Prefix | Netmask | Wildcard | Addresses | Usable hosts |
|---|---|---|---|---|
| /30 | 255.255.255.252 | 0.0.0.3 | 4 | 2 |
| /29 | 255.255.255.248 | 0.0.0.7 | 8 | 6 |
| /24 | 255.255.255.0 | 0.0.0.255 | 256 | 254 |
| /22 | 255.255.252.0 | 0.0.3.255 | 1,024 | 1,022 |
| /20 | 255.255.240.0 | 0.0.15.255 | 4,096 | 4,094 |
| /16 | 255.255.0.0 | 0.0.255.255 | 65,536 | 65,534 |
| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,216 | 16,777,214 |
Each extra bit in the prefix halves the block; each bit removed doubles it. The relationship \(N = 2^{32-p}\) is all you need to reconstruct any row of this table.
Frequently Asked Questions
How do I calculate a CIDR range by hand without a calculator?
Take the prefix length p and compute the block size \(N = 2^{32-p}\). Write the netmask as p one-bits followed by (32 − p) zero-bits: for /22 that is 11111111.11111111.11111100.00000000 = 255.255.252.0. AND your address with the mask to get the network address, then add \(N - 1\) to get the broadcast. Open question—simply rewrite: Two handy anchors: every octet covers 256 addresses, and each prefix bit halves the block, so /24 = 256, /23 = 512, /22 = 1024.
How do I convert a netmask like 255.255.240.0 to CIDR notation?
Convert the netmask to binary and count the one-bits. 255.255.240.0 = 11111111.11111111.11110000.00000000, which has 20 one-bits, so it is a /20. A shortcut: the mask octets are always 255, 254, 252, 248, 240, 224, 192, or 0 (256 minus a power of two), corresponding to 8, 7, 6, 5, 4, 3, 2, or 0 bits in that octet. 255+255+240+0 gives 8+8+4+0 = 20.
Why can't an arbitrary IP range be a single CIDR block?
A CIDR block of size \(2^k\) must start at an address divisible by \(2^k\). For example 192.168.1.16/28 is valid because 16 is a multiple of 16, but 192.168.1.8/28 is not a real block boundary. If your first and last addresses don't satisfy this alignment, the range must be split into several blocks — the greedy algorithm the calculator uses always produces the minimum possible number.
Does /24 mean the same as the old class C?
A /24 has the same size and netmask (255.255.255.0) as a class C network, but CIDR removed the fixed classes entirely — any prefix from /0 to /32 can be used on any address, so /24 says nothing about which class the address "belongs" to. What remain relevant today are the private ranges defined by RFC 1918: 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16. A CIDR block in those ranges is not routable on the public internet.
What is the wildcard mask used for?
The wildcard mask is the bitwise inverse of the netmask, so a /22 with netmask 255.255.252.0 has wildcard 0.0.3.255. It is mainly used in Cisco access control lists and OSPF network statements, where a 0 bit means "must match" and a 1 bit means "don't care". It is not the same as a subnet mask, so don't enter it where a netmask is expected — that is a common configuration mistake.
Why does 10.0.1.7/22 give the same results as 10.0.0.0/22?
10.0.1.7 is not the network address of the /22 block — its last 10 bits (the host bits) are not all zero. ANDing it with the /22 mask 255.255.252.0 clears those bits and yields the containing block 10.0.0.0/22, so the calculator describes that block. Always enter the network address if you want to be explicit; the calculation details will flag when your input had host bits set.
How many /26 subnets fit into a /22?
Compare the prefix difference: /22 → /26 is 4 bits, and each borrowed bit doubles the number of subnets, so \(2^4 = 16\) subnets of 64 addresses each (62 usable hosts). In general a /p block contains \(2^{q-p}\) subnets of size /q. If you need a fixed number of hosts per subnet instead, remember that a subnet for \(H\) hosts needs \(H + 2\) addresses (network and broadcast are reserved), rounded up to a power of two.