# IPv4 address distance

`ipv4-address-distance` · version 1.0.0 · URLs & IP addresses · free, no key needed

Compute the signed integer distance between two IPv4 addresses (address_b minus address_a).

**Use when you need to: ipv4 address distance · ipv4 address difference · how many ipv4 addresses apart.**

## Supported

- ipv4 address distance
- ipv4 address difference
- how many ipv4 addresses apart

## Not supported

- IPv6

## Behavior

- address_a and address_b are canonical dotted-decimal IPv4 addresses.
- difference is the canonical signed decimal integer string equal to address_b's uint32 value minus address_a's, in range -4294967295..4294967295.

## Input

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

## Output

- `difference` (string, required): max length 11; pattern `^-?(0|[1-9][0-9]*)$`

## Limits

- max address length: 15
- difference min: -4294967295
- difference max: 4294967295

## Example

Request input:

```json
{
  "address_a": "10.0.0.1",
  "address_b": "10.0.0.11"
}
```

Response:

```json
{
  "result": {
    "difference": "10"
  }
}
```

## How to call it

### MCP

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

```json
{
  "id": "ipv4-address-distance",
  "version": "1.0.0",
  "input": {
    "address_a": "10.0.0.1",
    "address_b": "10.0.0.11"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/ipv4-address-distance/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"address_a":"10.0.0.1","address_b":"10.0.0.11"}'
```

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

### CLI

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

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

## Related tools

- [IPv6 address distance](/tools/ipv6-address-distance): Compute the signed integer distance between two IPv6 addresses (address_b minus address_a).
- [IPv4 address compare](/tools/ipv4-address-compare): Compare two canonical IPv4 addresses by their numeric uint32 value.
- [IPv4 address classify](/tools/ipv4-address-classify): Classify an IPv4 address against the static IANA IPv4 special-purpose address registry.
- [IPv4 address offset](/tools/ipv4-address-offset): Add a signed integer offset to an IPv4 address, throwing if the result leaves the IPv4 address space.
- [IPv4 in CIDR](/tools/ipv4-in-cidr): Test whether a canonical IPv4 address lies in a CIDR prefix whose host bits are zero.
- [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.
