# IPv4 in CIDR

`ipv4-in-cidr` · version 1.0.0 · URLs & IP addresses · free, no key needed

Test whether a canonical IPv4 address lies in a CIDR prefix whose host bits are zero.

**Use when you need to: ipv4 in cidr · check ipv4 cidr membership · ipv4 address in network prefix.**

## Supported

- ipv4 in cidr
- check ipv4 cidr membership
- ipv4 address in network prefix

## Not supported

- IPv6
- IPv4-mapped IPv6
- ranges with hyphens
- dotted netmasks
- host bits ignored

## Behavior

- address is a canonical dotted-decimal IPv4 address (four octets 0-255, no leading zeros, no spaces, no hex).
- cidr is dotted-decimal/prefix with prefix a JSON-decimal integer 0-32 and no leading zeros except 0.
- The CIDR network address must have host bits zero; otherwise the tool throws CIDR host bits must be zero.
- inside is true iff the address uint32 is in [network, network + 2^(32-prefix) - 1].
- Prefix 32 matches only the address itself. Prefix 0 is valid only as 0.0.0.0/0 and matches every IPv4 address.
- network is the canonical dotted network address; prefix is a JSON integer.

## Input

- `address` (string, required): max length 15; pattern `^(?:0|[1-9][0-9]{0,2})(?:\.(?:0|[1-9][0-9]{0,2})){3}$`
- `cidr` (string, required): max length 18

## Output

- `inside` (boolean, required)
- `network` (string, required): max length 15
- `prefix` (integer, required): min 0; max 32

## Limits

- max address length: 15
- max cidr length: 18
- prefix min: 0
- prefix max: 32

## Example

Request input:

```json
{
  "address": "192.168.1.10",
  "cidr": "192.168.1.0/24"
}
```

Response:

```json
{
  "result": {
    "inside": true,
    "network": "192.168.1.0",
    "prefix": 24
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "ipv4-in-cidr",
  "version": "1.0.0",
  "input": {
    "address": "192.168.1.10",
    "cidr": "192.168.1.0/24"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/ipv4-in-cidr/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"address":"192.168.1.10","cidr":"192.168.1.0/24"}'
```

The machine-readable contract is at [/v1/tools/ipv4-in-cidr/versions/1.0.0](/v1/tools/ipv4-in-cidr/versions/1.0.0).

### CLI

```sh
node cli.mjs run ipv4-in-cidr 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [IPv6 in CIDR](/tools/ipv6-in-cidr): Test whether an IPv6 address lies in a CIDR prefix whose host bits are zero.
- [IPv4 CIDR contains](/tools/ipv4-cidr-contains): Test whether one IPv4 CIDR block fully contains another IPv4 CIDR block.
- [IPv4 CIDR overlap](/tools/ipv4-cidr-overlap): Test whether two IPv4 CIDR blocks overlap (share at least one address).
- [IPv4 CIDR parse](/tools/ipv4-cidr-parse): Parse an IPv4 CIDR block into its network, broadcast, netmask, wildcard mask, usable host range and address counts.
- [IPv4 range to cidrs](/tools/ipv4-range-to-cidrs): Convert an arbitrary IPv4 address range into the minimal list of CIDR blocks that exactly covers it.
- [IPv4 address classify](/tools/ipv4-address-classify): Classify an IPv4 address against the static IANA IPv4 special-purpose address registry.
