What does the CIDR Subnet & IP Calculator do?
The CIDR Subnet & IP Calculator computes network masks, broadcast addresses, first/last usable host IP ranges, and total host capacities from IPv4 Classless Inter-Domain Routing (CIDR) notation (e.g. 10.0.0.0/24 or 192.168.1.1/16). It provides full 32-bit binary breakdowns and identifies RFC 1918 private vs. public address spaces.
Core Concepts
Understanding CIDR prefix math and IPv4 address allocation:
- Prefix Length & Mask Calculation: The prefix integer (e.g.
/24) defines how many bits represent the network prefix, while remaining bits (32 - prefix) represent host identifiers. - Usable Host Space: Standard subnets reserve the first address for the Network ID and the last address for the Broadcast IP, yielding $2^{(32 - \text{prefix})} - 2$ assignable host addresses.
- Address Classification: Automatically detects RFC 1918 private network ranges (
10.0.0.0/8,172.16.0.0/12,192.168.0.0/16), loopback networks (127.0.0.0/8), and traditional IPv4 classes (A, B, C, D, E).
How to use the tool?
- Enter CIDR Notation: Type or paste any IPv4 address with a prefix (e.g.
192.168.1.0/24) into the input box or click Load Sample. - Calculate Metrics: Click Calculate CIDR Subnet to compute netmasks, host ranges, and binary representations.
- Copy & Export: Click Copy JSON or Download to export calculated subnet metrics for Terraform, CloudFormation, or network router configurations.
Related Developer Utilities
If you work with cloud networking, VPC infrastructure, and IP calculations, explore these complementary tools:
- IP Range to CIDR Calculator: Convert starting and ending IP ranges into optimal CIDR blocks.
- Subnet Mask & Wildcard Converter: Convert between subnet masks, wildcard masks, and CIDR prefixes.
- Port & Protocol Lookup: Search TCP/UDP port numbers, service names, and IANA assignments.
- AWS IP Ranges Search: Search official AWS IP ranges and generate security groups.
REST API Integration
Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/network/cidr-calculator) to programmatically compute IPv4 network metrics, subnet masks, usable host IP ranges, total host counts, wildcard masks, and binary representations.
API Request Parameters
| Name | Type | Description | Example |
|---|---|---|---|
rawText |
String | CIDR notation string or IPv4 address string to calculate. | "10.0.0.0/24" |
API Request Payload Examples
cURL
curl -X POST https://blueutils.com/api/network/cidr-calculator \
-H "Content-Type: application/json" \
-d '{
"rawText": "10.0.0.0/24"
}'Python
import requests
url = "https://blueutils.com/api/network/cidr-calculator"
payload = {"rawText": "172.16.0.0/16"}
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/24"
}
""";
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://blueutils.com/api/network/cidr-calculator"))
.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 CIDR calculation succeeded. | true |
cidr |
String | Normalized CIDR notation string. | "10.0.0.0/24" |
netmask |
String | Dotted-decimal subnet mask string. | "255.255.255.0" |
usableHostRange |
String | Usable host IP address range. | "10.0.0.1 - 10.0.0.254" |
totalHosts |
Number | Total count of addresses in the subnet. | 256 |
usableHosts |
Number | Total count of assignable host addresses. | 254 |
ipClass |
String | IPv4 address class designation. | "Class A" |
isPrivate |
Boolean | Whether IP falls within RFC 1918 private space. | true |
API Response Payload Examples
Success Response (HTTP 200 OK)
{
"isValid": true,
"cidr": "10.0.0.0/24",
"inputIp": "10.0.0.0",
"prefix": 24,
"netmask": "255.255.255.0",
"wildcardMask": "0.0.0.255",
"networkAddress": "10.0.0.0",
"broadcastAddress": "10.0.0.255",
"usableHostRange": "10.0.0.1 - 10.0.0.254",
"firstUsableIp": "10.0.0.1",
"lastUsableIp": "10.0.0.254",
"totalHosts": 256,
"usableHosts": 254,
"ipClass": "Class A",
"isPrivate": true,
"ipType": "Private (RFC 1918)",
"binaryIp": "00001010.00000000.00000000.00000000",
"binaryNetmask": "11111111.11111111.11111111.00000000",
"binaryNetwork": "00001010.00000000.00000000.00000000"
}Validation Failure Response (HTTP 400 Bad Request)
{
"isValid": false,
"error": "Invalid Prefix Length: \"40\". Must be an integer between 0 and 32."
}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 calculate CIDR subnets?
Integrating the CIDR Subnet Calculator API into cloud provisioning pipelines, Terraform modules, or infrastructure audit scripts provides key benefits:
- Rapid Script Validation: Dynamically computes VPC subnet masks, broadcast limits, and host counts before applying cloud infrastructure changes.
- Optimized Token Efficiency for AI Agents: LLMs frequently make bitwise math errors when calculating 32-bit subnet masks and usable host counts. Calling the API returns deterministic metrics without token hallucination.
- Deterministic Accuracy Without Hallucinations: Ensures 100% bitwise accurate calculations conforming strictly to RFC 1918 and IANA IPv4 specifications.
Native Usage
How to calculate CIDR metrics locally in terminal environments or scripts:
Windows (CMD / PowerShell)
# Calculate CIDR metrics using Python ipaddress module in PowerShell
python -c "import ipaddress; n = ipaddress.ip_network('10.0.0.0/24'); print('Netmask:', n.netmask, 'Usable Hosts:', n.num_addresses - 2)"Linux / Unix (Bash)
# Using ipcalc in Linux
ipcalc 10.0.0.0/24Python
Using Python standard library ipaddress:
import ipaddress
network = ipaddress.ip_network("10.0.0.0/24")
print(f"Netmask: {network.netmask}")
print(f"Broadcast: {network.broadcast_address}")
print(f"Total Hosts: {network.num_addresses}")
print(f"Usable Range: {list(network.hosts())[0]} - {list(network.hosts())[-1]}")Java
Using Java InetAddress and bitwise math:
import java.net.InetAddress;
public class CidrCalculatorExample {
public static void main(String[] args) throws Exception {
int prefix = 24;
int mask = prefix == 0 ? 0 : 0xFFFFFFFF << (32 - prefix);
byte[] bytes = new byte[] {
(byte)(mask >>> 24), (byte)(mask >>> 16), (byte)(mask >>> 8), (byte)mask
};
InetAddress netmask = InetAddress.getByAddress(bytes);
System.out.println("Subnet Mask: " + netmask.getHostAddress());
}
}