# IPv4 prefix for hosts

`ipv4-prefix-for-hosts` · version 1.0.0 · URLs & IP addresses · free, no key needed

Compute the smallest IPv4 CIDR block (largest prefix length) whose usable host capacity meets a required count.

**Use when you need to: ipv4 prefix for hosts · subnet size for host count · minimal ipv4 prefix for hosts.**

## Supported

- ipv4 prefix for hosts
- subnet size for host count
- minimal ipv4 prefix for hosts

## Not supported

- IPv6
- VLSM planning across multiple subnets

## Behavior

- usable_hosts is a JSON integer from 0 to 4294967294.
- Usable capacity follows RFC 3021: /32 has 1 usable host, /31 has 2, /0-/30 reserve network+broadcast so usable = 2^(32-prefix) - 2.
- prefix is the largest prefix length (smallest block) whose usable capacity is >= usable_hosts.

## Input

- `usable_hosts` (integer, required): min 0; max 4294967294

## Output

- `prefix` (integer, required): min 0; max 32
- `netmask` (string, required): max length 15
- `usable_host_count` (string, required): pattern `^(0|[1-9][0-9]*)$`
- `total_count` (string, required): pattern `^(0|[1-9][0-9]*)$`

## Limits

- usable hosts min: 0
- usable hosts max: 4294967294

## Example

Request input:

```json
{
  "usable_hosts": 60
}
```

Response:

```json
{
  "result": {
    "prefix": 26,
    "netmask": "255.255.255.192",
    "usable_host_count": "62",
    "total_count": "64"
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "ipv4-prefix-for-hosts",
  "version": "1.0.0",
  "input": {
    "usable_hosts": 60
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/ipv4-prefix-for-hosts/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"usable_hosts":60}'
```

The machine-readable contract is at [/v1/tools/ipv4-prefix-for-hosts/versions/1.0.0](/v1/tools/ipv4-prefix-for-hosts/versions/1.0.0).

### CLI

```sh
node cli.mjs run ipv4-prefix-for-hosts 1.0.0 --input input.json --base-url https://computefirst.net
```

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

## Related tools

- [IPv4 mask convert](/tools/ipv4-mask-convert): Convert between an IPv4 prefix length, dotted subnet netmask, and dotted wildcard (host) mask.
- [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 in CIDR](/tools/ipv4-in-cidr): Test whether a canonical IPv4 address lies in a CIDR prefix whose host bits are zero.
- [IPv4 address classify](/tools/ipv4-address-classify): Classify an IPv4 address against the static IANA IPv4 special-purpose address registry.
