IP Address Range to CIDR Calculator

IP Address Range to CIDR Calculator

Growing AI Skill PRO

Enter Calculation

Formula

CIDR=32−⌈log2⁡N⌉where{N=End−Start+1Start=int(Start IP)End=int(End IP)\begin{gathered} \text{CIDR} = 32 - \left\lceil \log_2 N \right\rceil \\[1.5em] \text{where}\quad \left\{ \begin{aligned} N &= \text{End} - \text{Start} + 1 \\ \text{Start} &= \text{int}\!\left(\text{Start IP}\right) \\ \text{End} &= \text{int}\!\left(\text{End IP}\right) \end{aligned} \right. \end{gathered}
Usage stats

Advertisement

Results

Smallest CIDR Prefix Covering the Range
/24
Addresses covered: 256
Addresses in range 256
CIDR block size (2^n) 256
Start IP (integer) 3,232,235,520
End IP (integer) 3,232,235,775

Report an error on this page

What is the IP Range to CIDR Calculator?

This tool takes a start and end IPv4 address and returns the smallest single CIDR block (a /prefix) large enough to cover the entire range. CIDR (Classless Inter-Domain Routing) notation expresses a block of addresses as a base address followed by a slash and a prefix length, such as 192.168.0.0/24. It is universal to IPv4 and works in any country or network.

How to use it

Enter the first address of your range in Start IP Address and the last address in End IP Address, then submit. The calculator converts both addresses to 32-bit integers, counts the addresses between them, and computes the prefix length of the smallest power-of-two block that contains them all.

Illustration of binary address bits split into a fixed network prefix and variable host portion
The prefix length marks where the fixed network bits end and host bits begin.

The formula explained

Each IPv4 address maps to a 32-bit integer. The number of addresses in the range is \(\text{count} = \text{end} - \text{start} + 1\). A CIDR block always holds a power-of-two number of addresses: a \(/n\) block holds \(2^{32-n}\) addresses. To cover \(\text{count}\) addresses we round up to the next power of two, $$\text{blockSize} = 2^{\lceil \log_2(\text{count}) \rceil}$$ then the prefix is $$32 - \log_2(\text{blockSize})$$

Advertisement

Worked example

Range 192.168.0.0 to 192.168.0.255. As integers these are 3,232235520 and 3,232235775, so \(\text{count} = 256\). Since \(256 = 2^8\), the block size is 256 and the prefix is $$32 - 8 = 24$$ giving /24.

Diagram showing a continuous IP address range from start to end broken into aligned CIDR blocks
A start-to-end range is covered by the smallest set of aligned CIDR blocks.

FAQ

Does the result always align to a CIDR boundary? The prefix is the smallest that fits the count, but a single CIDR block must also be address-aligned. If your start address is not on that boundary, the range may require multiple smaller blocks.

What if I enter them backwards? The calculator automatically swaps the start and end if the end is smaller.

Is this for IPv6 too? No — this tool covers IPv4 (32-bit) ranges only.

Last updated:

Most popular in Industry-Specific

View all Industry-Specific calculators