Skip to main content

IPv4 CIDR Calculator API

REAL DATA

Parse, split and compare strict IPv4 CIDR blocks or test membership, with canonical unsigned boundaries, exact subnet counts and no truncation.

Authoritative reference data or standards computation

Base URL
/api/ipv4-cidr
Capabilities
4 routes
Last updated
July 29, 2026
Data source

GET /api/ipv4-cidr/parse

Live requestRuns against the public API
No key required
GET/api/ipv4-cidr/parse?cidr=192.0.2.10%2F24

Request parameters

Strict dotted-decimal IPv4 CIDR. The address may be any member of the block; responses and meta.params canonicalize it to the network address.

Advanced response options4 options

Return only these fields (comma-separated). Mutually exclusive with 'exclude'.

Return all fields except these (comma-separated).

Pretty-print the JSON response.

Drop the envelope: return the raw array/object without data/meta wrapper.

Response

Example parameters are ready. Send the request to inspect the live response.

Route reference

Code samples Ready-to-copy requests in 4 languages
Choose a code sample language
curl "https://randomapi.dev/api/ipv4-cidr/parse?cidr=192.0.2.10%2F24"
const res = await fetch("https://randomapi.dev/api/ipv4-cidr/parse?cidr=192.0.2.10%2F24");
const { data, meta } = await res.json();
import requests

data = requests.get("https://randomapi.dev/api/ipv4-cidr/parse?cidr=192.0.2.10%2F24").json()["data"]
$json = json_decode(file_get_contents(
  "https://randomapi.dev/api/ipv4-cidr/parse?cidr=192.0.2.10%2F24"
), true);
$data = $json["data"];
Parameters Route-specific request inputs 1
cidr string required

Strict dotted-decimal IPv4 CIDR. The address may be any member of the block; responses and meta.params canonicalize it to the network address.

allowed: 9 – 18
example: cidr=192.0.2.10/24
Universal parameters Shared response and formatting options 4
fields list

Return only these fields (comma-separated). Mutually exclusive with 'exclude'.

example: fields=cidr,inputIp
exclude list

Return all fields except these (comma-separated).

example: exclude=usableHosts
pretty boolean

Pretty-print the JSON response.

default: false
example: pretty=true
unwrap boolean

Drop the envelope: return the raw array/object without data/meta wrapper.

default: false
example: unwrap=true
Response schema Fields returned in each record 11
cidr string

Canonical network address and prefix.

example: 192.0.2.0/24

inputIp string (IPv4)

Canonical address portion supplied in cidr before network alignment.

example: 192.0.2.10

network string (IPv4)

First address of the block.

example: 192.0.2.0

broadcast string (IPv4)

Last address of the block.

example: 192.0.2.255

prefix integer

CIDR prefix length from 0 through 32.

example: 24

netmask string (IPv4)

Dotted-decimal subnet mask.

example: 255.255.255.0

wildcardMask string (IPv4)

Inverse of the subnet mask.

example: 0.0.0.255

firstHost string (IPv4)

First usable address under the documented /31 and /32 rules.

example: 192.0.2.1

lastHost string (IPv4)

Last usable address under the documented /31 and /32 rules.

example: 192.0.2.254

totalAddresses integer

Total number of addresses, including network and broadcast where applicable.

example: 256

usableHosts integer

Usable host count: total minus two normally, two for /31, one for /32.

example: 254

Documented examples

Build-generated requests and complete responses
3
Calculate a documentation subnet
GET /api/ipv4-cidr/parse?cidr=192.0.2.10%2F24
{
  "data": {
    "cidr": "192.0.2.0/24",
    "inputIp": "192.0.2.10",
    "network": "192.0.2.0",
    "broadcast": "192.0.2.255",
    "prefix": 24,
    "netmask": "255.255.255.0",
    "wildcardMask": "0.0.0.255",
    "firstHost": "192.0.2.1",
    "lastHost": "192.0.2.254",
    "totalAddresses": 256,
    "usableHosts": 254
  },
  "meta": {
    "endpoint": "ipv4-cidr",
    "route": "/parse",
    "params": {
      "cidr": "192.0.2.0/24"
    },
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}
Inspect a point-to-point /31
GET /api/ipv4-cidr/parse?cidr=198.51.100.10%2F31
{
  "data": {
    "cidr": "198.51.100.10/31",
    "inputIp": "198.51.100.10",
    "network": "198.51.100.10",
    "broadcast": "198.51.100.11",
    "prefix": 31,
    "netmask": "255.255.255.254",
    "wildcardMask": "0.0.0.1",
    "firstHost": "198.51.100.10",
    "lastHost": "198.51.100.11",
    "totalAddresses": 2,
    "usableHosts": 2
  },
  "meta": {
    "endpoint": "ipv4-cidr",
    "route": "/parse",
    "params": {
      "cidr": "198.51.100.10/31"
    },
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}
The complete IPv4 address space
GET /api/ipv4-cidr/parse?cidr=203.0.113.9%2F0
{
  "data": {
    "cidr": "0.0.0.0/0",
    "inputIp": "203.0.113.9",
    "network": "0.0.0.0",
    "broadcast": "255.255.255.255",
    "prefix": 0,
    "netmask": "0.0.0.0",
    "wildcardMask": "255.255.255.255",
    "firstHost": "0.0.0.1",
    "lastHost": "255.255.255.254",
    "totalAddresses": 4294967296,
    "usableHosts": 4294967294
  },
  "meta": {
    "endpoint": "ipv4-cidr",
    "route": "/parse",
    "params": {
      "cidr": "0.0.0.0/0"
    },
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}

GET /api/ipv4-cidr/contains

Live requestRuns against the public API
No key required
GET/api/ipv4-cidr/contains?cidr=192.0.2.10%2F24&ip=192.0.2.42

Request parameters

Strict dotted-decimal IPv4 CIDR. The address may be any member of the block; responses and meta.params canonicalize it to the network address.

Strict dotted-decimal IPv4 address to test against the inclusive block boundaries.

Advanced response options4 options

Return only these fields (comma-separated). Mutually exclusive with 'exclude'.

Return all fields except these (comma-separated).

Pretty-print the JSON response.

Drop the envelope: return the raw array/object without data/meta wrapper.

Response

Example parameters are ready. Send the request to inspect the live response.

Route reference

Code samples Ready-to-copy requests in 4 languages
Choose a code sample language
curl "https://randomapi.dev/api/ipv4-cidr/contains?cidr=192.0.2.10%2F24&ip=192.0.2.42"
const res = await fetch("https://randomapi.dev/api/ipv4-cidr/contains?cidr=192.0.2.10%2F24&ip=192.0.2.42");
const { data, meta } = await res.json();
import requests

data = requests.get("https://randomapi.dev/api/ipv4-cidr/contains?cidr=192.0.2.10%2F24&ip=192.0.2.42").json()["data"]
$json = json_decode(file_get_contents(
  "https://randomapi.dev/api/ipv4-cidr/contains?cidr=192.0.2.10%2F24&ip=192.0.2.42"
), true);
$data = $json["data"];
Parameters Route-specific request inputs 2
cidr string required

Strict dotted-decimal IPv4 CIDR. The address may be any member of the block; responses and meta.params canonicalize it to the network address.

allowed: 9 – 18
example: cidr=192.0.2.10/24
ip string required

Strict dotted-decimal IPv4 address to test against the inclusive block boundaries.

allowed: 7 – 15
example: ip=192.0.2.42
Universal parameters Shared response and formatting options 4
fields list

Return only these fields (comma-separated). Mutually exclusive with 'exclude'.

example: fields=cidr,ip
exclude list

Return all fields except these (comma-separated).

example: exclude=broadcast
pretty boolean

Pretty-print the JSON response.

default: false
example: pretty=true
unwrap boolean

Drop the envelope: return the raw array/object without data/meta wrapper.

default: false
example: unwrap=true
Response schema Fields returned in each record 5
cidr string

Canonical network address and prefix.

example: 192.0.2.0/24

ip string (IPv4)

Canonical dotted-decimal address that was tested.

example: 192.0.2.42

contains boolean

Whether ip lies inside the inclusive network-to-broadcast range.

example: true

network string (IPv4)

First address of the CIDR block.

example: 192.0.2.0

broadcast string (IPv4)

Last address of the CIDR block.

example: 192.0.2.255

Documented examples

Build-generated requests and complete responses
3
Address inside the block
GET /api/ipv4-cidr/contains?cidr=192.0.2.10%2F24&ip=192.0.2.42
{
  "data": {
    "cidr": "192.0.2.0/24",
    "ip": "192.0.2.42",
    "contains": true,
    "network": "192.0.2.0",
    "broadcast": "192.0.2.255"
  },
  "meta": {
    "endpoint": "ipv4-cidr",
    "route": "/contains",
    "params": {
      "cidr": "192.0.2.0/24",
      "ip": "192.0.2.42"
    },
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}
Address outside the block
GET /api/ipv4-cidr/contains?cidr=192.0.2.0%2F24&ip=198.51.100.1
{
  "data": {
    "cidr": "192.0.2.0/24",
    "ip": "198.51.100.1",
    "contains": false,
    "network": "192.0.2.0",
    "broadcast": "192.0.2.255"
  },
  "meta": {
    "endpoint": "ipv4-cidr",
    "route": "/contains",
    "params": {
      "cidr": "192.0.2.0/24",
      "ip": "198.51.100.1"
    },
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}
The broadcast address is still contained
GET /api/ipv4-cidr/contains?cidr=203.0.113.0%2F24&ip=203.0.113.255
{
  "data": {
    "cidr": "203.0.113.0/24",
    "ip": "203.0.113.255",
    "contains": true,
    "network": "203.0.113.0",
    "broadcast": "203.0.113.255"
  },
  "meta": {
    "endpoint": "ipv4-cidr",
    "route": "/contains",
    "params": {
      "cidr": "203.0.113.0/24",
      "ip": "203.0.113.255"
    },
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}

GET /api/ipv4-cidr/subnets

Live requestRuns against the public API
No key required
GET/api/ipv4-cidr/subnets?cidr=192.0.2.99%2F24&newPrefix=26

Request parameters

Strict dotted-decimal IPv4 CIDR. The address may be any member of the block; responses and meta.params canonicalize it to the network address.

Child prefix; must be at least the canonical parent's prefix and produce no more than 256 children.

Advanced response options4 options

Return only these fields (comma-separated). Mutually exclusive with 'exclude'.

Return all fields except these (comma-separated).

Pretty-print the JSON response.

Drop the envelope: return the raw array/object without data/meta wrapper.

Response

Example parameters are ready. Send the request to inspect the live response.

Route reference

Code samples Ready-to-copy requests in 4 languages
Choose a code sample language
curl "https://randomapi.dev/api/ipv4-cidr/subnets?cidr=192.0.2.99%2F24&newPrefix=26"
const res = await fetch("https://randomapi.dev/api/ipv4-cidr/subnets?cidr=192.0.2.99%2F24&newPrefix=26");
const { data, meta } = await res.json();
import requests

data = requests.get("https://randomapi.dev/api/ipv4-cidr/subnets?cidr=192.0.2.99%2F24&newPrefix=26").json()["data"]
$json = json_decode(file_get_contents(
  "https://randomapi.dev/api/ipv4-cidr/subnets?cidr=192.0.2.99%2F24&newPrefix=26"
), true);
$data = $json["data"];
Parameters Route-specific request inputs 2
cidr string required

Strict dotted-decimal IPv4 CIDR. The address may be any member of the block; responses and meta.params canonicalize it to the network address.

allowed: 9 – 18
example: cidr=192.0.2.10/24
newPrefix int required

Child prefix; must be at least the canonical parent's prefix and produce no more than 256 children.

allowed: 0 – 32
example: newPrefix=26
Universal parameters Shared response and formatting options 4
fields list

Return only these fields (comma-separated). Mutually exclusive with 'exclude'.

example: fields=cidr,newPrefix
exclude list

Return all fields except these (comma-separated).

example: exclude=subnets
pretty boolean

Pretty-print the JSON response.

default: false
example: pretty=true
unwrap boolean

Drop the envelope: return the raw array/object without data/meta wrapper.

default: false
example: unwrap=true
Response schema Fields returned in each record 5
cidr string

Canonical parent network and prefix.

example: 192.0.2.0/24

newPrefix integer

Requested aligned child prefix.

example: 26

subnetCount integer

Exact number of children: 2^(newPrefix - parent prefix).

example: 4

addressesPerSubnet integer

Exact address count in every child block.

example: 64

subnets object[]

Complete ordered child list with canonical CIDR and inclusive boundaries; never truncated.

example: [{"cidr":"192.0.2.0/26","network":"192.0.2.0","broadcast":"192.0.2.63"}]

Documented examples

Build-generated requests and complete responses
3
Split a /24 into four /26 blocks
GET /api/ipv4-cidr/subnets?cidr=192.0.2.99%2F24&newPrefix=26
{
  "data": {
    "cidr": "192.0.2.0/24",
    "newPrefix": 26,
    "subnetCount": 4,
    "addressesPerSubnet": 64,
    "subnets": [
      {
        "cidr": "192.0.2.0/26",
        "network": "192.0.2.0",
        "broadcast": "192.0.2.63"
      },
      {
        "cidr": "192.0.2.64/26",
        "network": "192.0.2.64",
        "broadcast": "192.0.2.127"
      },
      {
        "cidr": "192.0.2.128/26",
        "network": "192.0.2.128",
        "broadcast": "192.0.2.191"
      },
      {
        "cidr": "192.0.2.192/26",
        "network": "192.0.2.192",
        "broadcast": "192.0.2.255"
      }
    ]
  },
  "meta": {
    "endpoint": "ipv4-cidr",
    "route": "/subnets",
    "params": {
      "cidr": "192.0.2.0/24",
      "newPrefix": 26
    },
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}
Enumerate all 256 hosts as /32 children
GET /api/ipv4-cidr/subnets?cidr=198.51.100.0%2F24&newPrefix=32
{
  "data": {
    "cidr": "198.51.100.0/24",
    "newPrefix": 32,
    "subnetCount": 256,
    "addressesPerSubnet": 1,
    "subnets": [
      {
        "cidr": "198.51.100.0/32",
        "network": "198.51.100.0",
        "broadcast": "198.51.100.0"
      },
      {
        "cidr": "198.51.100.1/32",
        "network": "198.51.100.1",
        "broadcast": "198.51.100.1"
      },
      {
        "cidr": "198.51.100.2/32",
        "network": "198.51.100.2",
        "broadcast": "198.51.100.2"
      },
      {
        "cidr": "198.51.100.3/32",
        "network": "198.51.100.3",
        "broadcast": "198.51.100.3"
      },
      {
        "cidr": "198.51.100.4/32",
        "network": "198.51.100.4",
        "broadcast": "198.51.100.4"
      },
      {
        "cidr": "198.51.100.5/32",
        "network": "198.51.100.5",
        "broadcast": "198.51.100.5"
      },
      {
        "cidr": "198.51.100.6/32",
        "network": "198.51.100.6",
    …
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}
Keep a high-bit block at its current prefix
GET /api/ipv4-cidr/subnets?cidr=250.200.199.129%2F25&newPrefix=25
{
  "data": {
    "cidr": "250.200.199.128/25",
    "newPrefix": 25,
    "subnetCount": 1,
    "addressesPerSubnet": 128,
    "subnets": [
      {
        "cidr": "250.200.199.128/25",
        "network": "250.200.199.128",
        "broadcast": "250.200.199.255"
      }
    ]
  },
  "meta": {
    "endpoint": "ipv4-cidr",
    "route": "/subnets",
    "params": {
      "cidr": "250.200.199.128/25",
      "newPrefix": 25
    },
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}

GET /api/ipv4-cidr/overlaps

Live requestRuns against the public API
No key required
GET/api/ipv4-cidr/overlaps?a=192.0.2.99%2F24&b=192.0.2.200%2F25

Request parameters

First strict dotted-decimal IPv4 CIDR; canonicalized to its aligned network block.

Second strict dotted-decimal IPv4 CIDR; canonicalized before comparison.

Advanced response options4 options

Return only these fields (comma-separated). Mutually exclusive with 'exclude'.

Return all fields except these (comma-separated).

Pretty-print the JSON response.

Drop the envelope: return the raw array/object without data/meta wrapper.

Response

Example parameters are ready. Send the request to inspect the live response.

Route reference

Code samples Ready-to-copy requests in 4 languages
Choose a code sample language
curl "https://randomapi.dev/api/ipv4-cidr/overlaps?a=192.0.2.99%2F24&b=192.0.2.200%2F25"
const res = await fetch("https://randomapi.dev/api/ipv4-cidr/overlaps?a=192.0.2.99%2F24&b=192.0.2.200%2F25");
const { data, meta } = await res.json();
import requests

data = requests.get("https://randomapi.dev/api/ipv4-cidr/overlaps?a=192.0.2.99%2F24&b=192.0.2.200%2F25").json()["data"]
$json = json_decode(file_get_contents(
  "https://randomapi.dev/api/ipv4-cidr/overlaps?a=192.0.2.99%2F24&b=192.0.2.200%2F25"
), true);
$data = $json["data"];
Parameters Route-specific request inputs 2
a string required

First strict dotted-decimal IPv4 CIDR; canonicalized to its aligned network block.

allowed: 9 – 18
example: a=192.0.2.0/24
b string required

Second strict dotted-decimal IPv4 CIDR; canonicalized before comparison.

allowed: 9 – 18
example: b=192.0.2.128/25
Universal parameters Shared response and formatting options 4
fields list

Return only these fields (comma-separated). Mutually exclusive with 'exclude'.

example: fields=a,b
exclude list

Return all fields except these (comma-separated).

example: exclude=intersectionAddressCount
pretty boolean

Pretty-print the JSON response.

default: false
example: pretty=true
unwrap boolean

Drop the envelope: return the raw array/object without data/meta wrapper.

default: false
example: unwrap=true
Response schema Fields returned in each record 8
a string

Canonical first CIDR block.

example: 192.0.2.0/24

b string

Canonical second CIDR block.

example: 192.0.2.128/25

overlap boolean

Whether the inclusive address ranges intersect.

example: true

relation string

equal, aContainsB, bContainsA or disjoint.

example: aContainsB

intersectionCidr string nullable

Exact intersecting CIDR (the more specific block), or null when disjoint.

example: 192.0.2.128/25

intersectionNetwork string (IPv4) nullable

First intersection address, or null when disjoint.

example: 192.0.2.128

intersectionBroadcast string (IPv4) nullable

Last intersection address, or null when disjoint.

example: 192.0.2.255

intersectionAddressCount integer nullable

Exact intersection size, or null when disjoint.

example: 128

Documented examples

Build-generated requests and complete responses
3
A contains B after canonicalization
GET /api/ipv4-cidr/overlaps?a=192.0.2.99%2F24&b=192.0.2.200%2F25
{
  "data": {
    "a": "192.0.2.0/24",
    "b": "192.0.2.128/25",
    "overlap": true,
    "relation": "aContainsB",
    "intersectionCidr": "192.0.2.128/25",
    "intersectionNetwork": "192.0.2.128",
    "intersectionBroadcast": "192.0.2.255",
    "intersectionAddressCount": 128
  },
  "meta": {
    "endpoint": "ipv4-cidr",
    "route": "/overlaps",
    "params": {
      "a": "192.0.2.0/24",
      "b": "192.0.2.128/25"
    },
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}
Two adjacent blocks are disjoint
GET /api/ipv4-cidr/overlaps?a=198.51.100.0%2F25&b=198.51.100.128%2F25
{
  "data": {
    "a": "198.51.100.0/25",
    "b": "198.51.100.128/25",
    "overlap": false,
    "relation": "disjoint",
    "intersectionCidr": null,
    "intersectionNetwork": null,
    "intersectionBroadcast": null,
    "intersectionAddressCount": null
  },
  "meta": {
    "endpoint": "ipv4-cidr",
    "route": "/overlaps",
    "params": {
      "a": "198.51.100.0/25",
      "b": "198.51.100.128/25"
    },
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}
The full IPv4 space contains a high-bit block
GET /api/ipv4-cidr/overlaps?a=255.255.255.255%2F0&b=250.200.199.129%2F25
{
  "data": {
    "a": "0.0.0.0/0",
    "b": "250.200.199.128/25",
    "overlap": true,
    "relation": "aContainsB",
    "intersectionCidr": "250.200.199.128/25",
    "intersectionNetwork": "250.200.199.128",
    "intersectionBroadcast": "250.200.199.255",
    "intersectionAddressCount": 128
  },
  "meta": {
    "endpoint": "ipv4-cidr",
    "route": "/overlaps",
    "params": {
      "a": "0.0.0.0/0",
      "b": "250.200.199.128/25"
    },
    "generatedAt": "2026-07-29T08:13:22.000Z"
  }
}

About this API

Coverage & behavior

Calculates IPv4 CIDR boundaries with exact unsigned arithmetic. Pass any address inside a block, such as 192.0.2.10/24, and the API canonicalizes it to 192.0.2.0/24 before returning its network, broadcast, masks and usable host range.

Input is deliberately strict: exactly four decimal octets and a prefix from 0 through 32. Shorthand, hexadecimal, leading-zero octets, trailing junk and IPv6 are rejected instead of being guessed.

For ordinary prefixes, the network and broadcast addresses are excluded from usableHosts. RFC 3021 semantics apply to /31: both addresses are usable on a point-to-point link. A /32 contains one host route.

/subnets splits a parent into every aligned child at newPrefix. Counts and address sizes are exact; requests producing more than 256 children return 400 rather than truncating a mathematically complete result. /overlaps canonicalizes two blocks and reports whether they are equal, one contains the other, or they are disjoint. Aligned CIDR blocks cannot partially overlap, so any intersection is exactly the more specific block.

Use it for

  • Validate firewall and allow-list CIDRs before storing configuration
  • Show network, broadcast and host ranges in an infrastructure UI
  • Test whether a client or service IPv4 address belongs to a configured block
  • Split an allocation into a complete bounded list of aligned child subnets
  • Classify equality, containment or disjointness between two CIDR rules

Frequently asked questions

Does the API canonicalize host addresses inside a CIDR?

Yes. 192.0.2.10/24 is resolved and echoed as the canonical block 192.0.2.0/24, while inputIp preserves the tested host address.

How are /31 and /32 networks counted?

A /31 reports both addresses as usable point-to-point addresses under RFC 3021. A /32 reports its single address as the only usable host.

Does this CIDR calculator accept IPv6 or shorthand IPv4?

No. This endpoint is intentionally IPv4-only and requires four canonical decimal octets; unsupported or ambiguous forms return a 400 naming cidr or ip.

Will subnet splitting silently truncate a large result?

No. /subnets returns every child when the exact count is at most 256 and returns 400 when the requested split would produce 257 or more children.

Can two aligned CIDR blocks overlap only partially?

No. Two canonical CIDR blocks are either disjoint, equal, or one completely contains the other; the intersection is therefore the more specific block.

Standards & references