IPv4 Subnet Calculator API¶
Overview¶
Calculate an IPv4 subnet report from an IP address and either a CIDR prefix or subnet mask. This endpoint accepts a JSON request body and responds synchronously with the report serialized as a string in preview.
Endpoint¶
| Method | Path | URL |
|---|---|---|
POST | /ipv4-subnet-calculator-api | https://api.apidatatools.com/ipv4-subnet-calculator-api |
Authentication¶
Send your API key in the x-api-key header.
Input modes¶
This converter supports body mode. Requests are processed synchronously. URL and pre-uploaded-file input modes are not documented for this endpoint.
Headers¶
Header names are case-insensitive.
| Header | Type | Required | Default / values | Description |
|---|---|---|---|---|
x-api-key | string | Yes | No default | API key used to authenticate the request. |
x-source-type | string | No | Default: body. Use body for this endpoint. | Selects the request input mode. |
Request body¶
Send a JSON object with an IPv4 address and either a CIDR prefix or a subnet mask.
| Field | Type | Required | Description |
|---|---|---|---|
ip | string | Yes | IPv4 address to analyze. |
cidr | integer or integer string | One of cidr or mask is required | CIDR prefix from 0 through 32. If both cidr and mask are supplied, cidr is used. |
mask | string | One of cidr or mask is required | IPv4 subnet mask in dotted-decimal notation, such as 255.255.255.0. |
The network is calculated with non-strict network parsing: if the supplied IP has host bits set, the report uses the containing network.
curl example¶
curl --request POST \
--url 'https://api.apidatatools.com/ipv4-subnet-calculator-api' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'x-source-type: body' \
--data-raw '{"ip":"192.168.1.10","cidr":30}'
Success responses¶
A successful request returns HTTP 200 with a JSON response containing:
| Field | Type | Description |
|---|---|---|
request_id | string | Identifier for the request. |
status | string | success when the request completes. |
preview | string | The subnet report serialized as JSON text. |
The serialized report in preview contains:
| Report field | Description |
|---|---|
ip_address | Supplied IP in quads, 32-bit binary, uppercase hex, and numeric integer formats. |
subnet_mask | Subnet mask in the same four formats. |
cidr | Network prefix length. |
network | Network address in the same four formats. |
broadcast | Broadcast address in the same four formats. |
wildcard_mask | Wildcard mask as a dotted-decimal string. |
total_ips | Total number of addresses in the network. |
usable_hosts | Usable host count reported for the network. |
first_host | First host address reported for the network. |
last_host | Last host address reported for the network. |
range | Network and broadcast addresses formatted as a range string. |
hosts | List of host addresses when the network has at most 1,024 addresses; otherwise the string Too large to list. |
ip_type | Boolean flags: is_private, is_loopback, is_multicast, is_link_local, is_reserved, and is_global. These flags are calculated from the network address. |
For /31 networks, both addresses are counted as usable hosts. For /32 networks, the single address is counted as usable.
Error handling¶
Errors use an envelope with status, error, request_id, and details.message. Additional fields may appear in details.
| HTTP status | Error code(s) | Meaning |
|---|---|---|
400 | INVALID_JSON | The body is not a valid JSON object. |
400 | MISSING_IP | The ip field is missing or empty. |
400 | MISSING_MASK_OR_CIDR | Neither cidr nor mask was provided. |
400 | INVALID_CIDR | The CIDR value is not an integer or is outside 0–32. |
400 | INVALID_MASK | The subnet mask is invalid. |
400 | INVALID_SUBNET | The supplied IP or subnet could not be used to form an IPv4 subnet. |
400 | PROCESSING_ERROR | The subnet report could not be generated. |
400 | INVALID_SOURCE_TYPE | The x-source-type value is not accepted. |
400 | INVALID_BODY_ENCODING | The request body could not be decoded. |
400 | EMPTY_BODY | The request body is empty. |
401 | UNAUTHORIZED | Authentication failed or was not provided. |
404 | USER_NOT_FOUND | The authenticated user could not be found. |
404 | UNKNOWN_FUNCTION | The requested API endpoint is not supported. |
413 | PAYLOAD_TOO_LARGE | The request body exceeds the limit for the current plan. |
429 | QUOTA_EXCEEDED | The current plan’s request quota has been exhausted. |
429 | RATE_LIMITED | The request rate exceeds the current plan’s limit. |
500 | PLAN_NOT_FOUND | Plan configuration could not be found. |
500 | INTERNAL_ERROR | An unexpected processing error occurred. |
Notes¶
- Request-body size, quota, and rate limits depend on the plan. See tool limits for details.
- The
previewvalue is serialized JSON text, not a JSON object.