# CIDR and subnet calculator

Work out the network, netmask, host range and size of an IPv4 or IPv6 CIDR block, and split it into subnets.

- Endpoint: `POST https://setget.net/v1/tools/cidr-calc` with JSON `{"input": {...}}`
- MCP: `run_tool` with `slug` = `cidr-calc`
- Page: https://setget.net/tools/cidr-calc

## Inputs

- `cidr` (required, string): The block in CIDR form, such as 192.168.1.0/24 or 2001:db8::/48.
- `addresses` (optional, array): IP addresses to test for being inside the block.
- `new_prefix` (optional, integer, range 0..128): Split the block into subnets of this prefix length. The first 256 are listed.

## Example 1

```json
{"input":{"cidr":"192.168.1.0/24","addresses":["192.168.1.77","192.168.2.1"]}}
```

Result:

```json
{"cidr":"192.168.1.0/24","version":4,"network":"192.168.1.0","prefix":24,"netmask":"255.255.255.0","wildcard":"0.0.0.255","broadcast":"192.168.1.255","first_host":"192.168.1.1","last_host":"192.168.1.254","total_addresses":256,"usable_hosts":254,"scope":"private","is_private":true,"is_loopback":false,"is_link_local":false,"is_reserved":false,"host_bits_set":false,"contains":[{"address":"192.168.1.77","inside":true},{"address":"192.168.2.1","inside":false}],"subnets":null}
```

## Example 2: Split into /24 subnets

```json
{"input":{"cidr":"10.0.0.0/22","new_prefix":24}}
```

Result:

```json
{"cidr":"10.0.0.0/22","version":4,"network":"10.0.0.0","prefix":22,"netmask":"255.255.252.0","wildcard":"0.0.3.255","broadcast":"10.0.3.255","first_host":"10.0.0.1","last_host":"10.0.3.254","total_addresses":1024,"usable_hosts":1022,"scope":"private","is_private":true,"is_loopback":false,"is_link_local":false,"is_reserved":false,"host_bits_set":false,"contains":[],"subnets":{"prefix":24,"count":4,"addresses_each":256,"truncated":false,"listed":["10.0.0.0/24","10.0.1.0/24","10.0.2.0/24","10.0.3.0/24"]}}
```

**Why are two addresses not usable in IPv4?** The first address names the network and the last is the broadcast address. A /31 (two hosts, point-to-point links) and a /32 (one host) are the exceptions.

**Why are some counts in quotes?** Numbers above 2^53, common for IPv6, are returned as text so that no JSON reader rounds them.

**What does scope "mixed" mean?** The block is partly public and partly special-purpose space, for example 0.0.0.0/0.
