What does the IP Range to CIDR Calculator do?
The IP Range to CIDR Calculator aggregates arbitrary starting and ending IPv4 address spans (such as 10.0.0.0 to 10.0.3.255) into the minimal set of valid, non-overlapping Classless Inter-Domain Routing (CIDR) subnet blocks (10.0.0.0/22). It provides network metrics for each calculated block, including netmask, network address, total hosts, and exact start/end IP boundaries.
Core Concepts
Understanding why arbitrary IP ranges produce multiple CIDR blocks helps design VPC routing and security rules:
- Binary Power-of-Two Alignment: CIDR subnet blocks must start on binary boundaries matching their prefix length. If an IP address range does not begin on a natural power-of-two boundary, multiple smaller adjacent CIDRs are calculated to cover the span without overlapping.
- Maximal Subnet Allocation: The calculator greedily identifies the largest power-of-two prefix block that fits within remaining address space, ensuring the minimal number of CIDRs.
- Cloud Security Group Compliance: Cloud providers (AWS, Azure, Google Cloud) require firewall ingress/egress rules to be declared as CIDRs rather than continuous IP ranges.
How to use the tool?
- Enter IP Range: Enter your starting and ending IPv4 addresses separated by a hyphen (
-), the wordto, or a comma (e.g.192.168.1.0 - 192.168.1.255or10.0.0.0 to 10.0.3.255). - Calculate CIDRs: Click Convert IP Range to CIDR to compute the minimal list of covering subnets.
- Copy or Export: Copy the resulting CIDR notation list for direct use in Terraform scripts, AWS Security Groups, or router access control lists.
Related Developer Utilities
If you are managing network subnets, routing rules, or cloud VPC security, explore these complementary tools:
- CIDR Subnet Calculator: Calculate usable host counts, broadcast IPs, and netmasks for any CIDR block.
- Subnet Mask Converter: Convert between standard subnet masks, Cisco wildcard masks, and CIDR prefixes.
- Port & Protocol Lookup: Search TCP/UDP port numbers, standard service names, and IANA assignments.
- AWS Security Group IP Ranges: Search official AWS IP prefix blocks to configure automated cloud firewalls.
REST API Integration
Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/network/ip-range-to-cidr) to programmatically convert IP address ranges (start IP and end IP) into minimal CIDR subnet blocks.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText |
String | Starting and ending IPv4 range separated by -, to, or ,. |
"192.168.1.0 - 192.168.1.255" |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/network/ip-range-to-cidr \
-H "Content-Type: application/json" \
-d '{
"rawText": "192.168.1.0 - 192.168.1.255"
}'Python
import requests
url = "https://blueutils.com/api/network/ip-range-to-cidr"
payload = { "rawText": "192.168.1.0 - 192.168.1.255" }
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
String jsonPayload = """
{
"rawText": "192.168.1.0 - 192.168.1.255"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/network/ip-range-to-cidr"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}API Response Parameters
| Name | Type | Description | Example |
|---|---|---|---|
isValid |
Boolean | Indicates whether the range conversion succeeded. | true |
startIp |
String | Parsed starting IPv4 address. | "192.168.1.0" |
endIp |
String | Parsed ending IPv4 address. | "192.168.1.255" |
totalHosts |
Integer | Total number of IP addresses in the span. | 256 |
totalCidrs |
Integer | Total number of minimal CIDR subnet blocks. | 1 |
cidrList |
Array | Array of CIDR notation strings covering the range. | ["192.168.1.0/24"] |
cidrBlocks |
Array | Detailed objects containing cidr, networkAddress, prefix, netmask, totalHosts, startIp, endIp. |
[...] |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"startIp": "192.168.1.0",
"endIp": "192.168.1.255",
"totalHosts": 256,
"totalCidrs": 1,
"cidrList": [
"192.168.1.0/24"
],
"cidrBlocks": [
{
"cidr": "192.168.1.0/24",
"networkAddress": "192.168.1.0",
"prefix": 24,
"netmask": "255.255.255.0",
"totalHosts": 256,
"startIp": "192.168.1.0",
"endIp": "192.168.1.255"
}
]
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Invalid Start IPv4 Address format: \"300.0.0.1\". Expected format e.g. 192.168.1.0"
}Rate Limit Exceeded Response (HTTP 429 Too Many Requests)
{
"error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}Why use an API to convert IP ranges to CIDR?
Integrating the IP Range to CIDR API into cloud automation scripts, Terraform providers, or CI/CD network provisioning pipelines provides key advantages:
- Rapid Script Validation: Enables automated security scripts to convert vendor IP whitelist ranges into valid CIDR blocks for cloud firewall rules without calculation errors.
- Optimized Token Efficiency for AI Agents: Offloads complex bitwise binary arithmetic and boundary alignment to an external endpoint, saving prompt tokens.
- Deterministic Accuracy Without Hallucinations: Ensures mathematically optimal prefix block aggregation without subnet overlap or omitted host addresses.
Native Usage
How to convert IP address ranges to CIDR blocks locally in your terminal:
Windows (CMD / PowerShell)
# Using Python ipaddress module in PowerShell
python -c "
import ipaddress
start = ipaddress.IPv4Address('192.168.1.0')
end = ipaddress.IPv4Address('192.168.1.255')
cidrs = list(ipaddress.summarize_address_range(start, end))
print([str(c) for c in cidrs])
"Linux / Unix (Bash)
# Using ipcalc or Python CLI to summarize IP ranges
python3 -c "import ipaddress; print([str(c) for c in ipaddress.summarize_address_range(ipaddress.IPv4Address('192.168.1.0'), ipaddress.IPv4Address('192.168.1.255'))])"Python
Using Python standard library ipaddress:
import ipaddress
start_ip = ipaddress.IPv4Address("10.0.0.0")
end_ip = ipaddress.IPv4Address("10.0.3.255")
cidr_blocks = list(ipaddress.summarize_address_range(start_ip, end_ip))
for block in cidr_blocks:
print(f"CIDR Block: {block} ({block.num_addresses} addresses)")Java
Using standard Java bitwise operations to compute CIDR prefix blocks:
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
public class IpRangeToCidr {
public static long ipToLong(String ip) throws Exception {
byte[] octets = InetAddress.getByName(ip).getAddress();
long result = 0;
for (byte b : octets) {
result = (result << 8) | (b & 0xFF);
}
return result;
}
public static String longToIp(long ip) throws Exception {
return InetAddress.getByAddress(new byte[]{
(byte) (ip >>> 24),
(byte) (ip >>> 16),
(byte) (ip >>> 8),
(byte) ip
}).getHostAddress();
}
public static void main(String[] args) throws Exception {
long start = ipToLong("192.168.1.0");
long end = ipToLong("192.168.1.255");
long current = start;
List<String> cidrs = new ArrayList<>();
while (current <= end) {
int maxSize = 0;
while ((current & (1L << maxSize)) == 0 && (current + (1L << (maxSize + 1)) - 1) <= end && maxSize < 32) {
maxSize++;
}
int prefix = 32 - maxSize;
cidrs.add(longToIp(current) + "/" + prefix);
current += (1L << maxSize);
}
System.out.println("Computed CIDRs: " + cidrs);
}
}