# IPv4 CIDR Subnet Calculator (`ask4favour/ipv4-cidr-subnet-calculator`) Actor

Calculate IPv4 CIDR subnet ranges, network and broadcast addresses, subnet masks, usable IP addresses, and host counts for networking, DevOps, infrastructure automation, and firewall configuration.

- **URL**: https://apify.com/ask4favour/ipv4-cidr-subnet-calculator.md
- **Developed by:** [Ask4Favour](https://apify.com/ask4favour) (community)
- **Stats:** 2 total users, 1 monthly users, 75.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

This **IPv4 CIDR subnet calculator** converts CIDR notation into a network address, broadcast address, subnet mask, usable IP range, and host count. Enter an IPv4 address with a prefix, such as `192.168.1.10/24`, or calculate multiple subnets in an ordered batch with structured JSON results for scripts and AI agents.

All calculations are deterministic and run inside the Actor without contacting external IP lookup services.

### CIDR to IP range, subnet mask, and host count

#### Convert CIDR to an IP address range

For `192.168.1.10/24`, the complete IP range is `192.168.1.0` through `192.168.1.255`; the usable host range is `192.168.1.1` through `192.168.1.254`. The canonical network CIDR is `192.168.1.0/24`, even when the input contains a host address.

#### Find the subnet mask and usable host count

Use the subnet mask calculator to translate a prefix length into dotted-decimal notation and check subnet capacity:

| CIDR prefix | Subnet mask | Total addresses | Usable hosts |
| --- | --- | ---: | ---: |
| `/24` | `255.255.255.0` | 256 | 254 |
| `/27` | `255.255.255.224` | 32 | 30 |
| `/30` | `255.255.255.252` | 4 | 2 |

These are standard IPv4 host counts; cloud providers may reserve additional addresses.

### Subnet planning for DevOps, firewalls, and IP address management

- Plan AWS VPC, Azure VNet, Google Cloud, Kubernetes, and on-premises subnets.
- Check whether a subnet has enough usable IP addresses for servers or devices.
- Convert CIDR notation into IP ranges for firewall rules and access control lists.
- Validate network and broadcast addresses during infrastructure automation.
- Add deterministic IPv4 calculations to DevOps workflows, scripts, and AI agents.
- Process multiple CIDR blocks for IP address management and network audits.

### How to calculate an IPv4 subnet

1. Open the Actor in Apify Console.
2. Enter an IPv4 address followed by a CIDR prefix, such as `192.168.1.10/24`.
3. Click **Start**.
4. Open the run's **Dataset** to view or download the calculated subnet data.

Provide one of these input fields:

The input form prefills `192.168.1.10/24`; clear it when using `cidrs` for a batch. If both fields are omitted (including input `{}`), the Actor calculates this example subnet automatically.

| Field | Type | Description |
| --- | --- | --- |
| `cidr` | string | One IPv4 address with a `/0`–`/32` prefix, such as `10.0.0.5/24` |
| `cidrs` | string array | Multiple IPv4 CIDRs to calculate as an ordered batch |

#### Single CIDR input

```json
{
  "cidr": "192.168.1.10/24"
}
```

#### Batch IPv4 subnet calculations

Submit an array to calculate multiple IPv4 subnets in the same order:

```json
{
  "cidrs": [
    "192.168.1.10/24",
    "10.0.0.1/30",
    "172.16.5.100/16"
  ]
}
```

### IPv4 subnet calculator output

Each input CIDR produces one item in the default dataset:

```json
{
  "input": "192.168.1.10/24",
  "networkAddress": "192.168.1.0",
  "broadcastAddress": "192.168.1.255",
  "subnetMask": "255.255.255.0",
  "firstUsableHost": "192.168.1.1",
  "lastUsableHost": "192.168.1.254",
  "totalAddresses": 256,
  "usableHostCount": 254,
  "canonicalNetworkCidr": "192.168.1.0/24"
}
```

| Field | Description |
| --- | --- |
| `input` | Original IPv4 CIDR submitted to the Actor |
| `networkAddress` | First address in the subnet |
| `broadcastAddress` | Last address in the subnet |
| `subnetMask` | Dotted-decimal IPv4 subnet mask |
| `firstUsableHost` | First usable host address |
| `lastUsableHost` | Last usable host address |
| `totalAddresses` | Total number of addresses in the CIDR block |
| `usableHostCount` | Number of usable host addresses |
| `canonicalNetworkCidr` | Normalized network address and prefix |
| `error` | Validation error code and message for an invalid batch entry |
| `index` | Zero-based position of an invalid entry in a batch |

### IPv4 `/31` and `/32` subnet calculation examples

The Actor accepts IPv4 CIDR notation only; IPv6 is not supported. Prefixes `/0` through `/30` reserve the network and broadcast addresses, `/31` treats both addresses as usable according to RFC 3021, and `/32` represents one host address.

| Input | Network | Broadcast | First usable | Last usable | Total | Usable |
| --- | --- | --- | --- | --- | ---: | ---: |
| `10.0.0.0/31` | `10.0.0.0` | `10.0.0.1` | `10.0.0.0` | `10.0.0.1` | 2 | 2 |
| `8.8.8.8/32` | `8.8.8.8` | `8.8.8.8` | `8.8.8.8` | `8.8.8.8` | 1 | 1 |

#### Invalid CIDR input and batch errors

IPv6 addresses, missing prefixes, and prefixes outside `/0`–`/32` are unsupported. Apify validates inputs against the input schema before starting a run.

Invalid entries that reach the calculator produce structured error items. In a batch, valid entries are still calculated and retain their input order, but the Actor run finishes with a nonzero status if any entry is invalid.

# Actor input Schema

## `cidr` (type: `string`):

One IPv4 address with a /0 through /32 CIDR prefix, such as 10.0.0.5/24. Use CIDRs for a batch instead. If both fields are omitted, calculates 192.168.1.10/24.

## `cidrs` (type: `array`):

IPv4 addresses with /0 through /32 CIDR prefixes to calculate as an ordered batch. Leave this empty when using IPv4 CIDR above.

## Actor input object example

```json
{
  "cidr": "10.0.0.5/24",
  "cidrs": [
    "192.168.1.10/24",
    "10.0.0.1/30"
  ]
}
```

# Actor output Schema

## `results` (type: `string`):

One default-dataset item per input CIDR, in input order. Each successful item identifies input, networkAddress, broadcastAddress, subnetMask, firstUsableHost, lastUsableHost, totalAddresses, usableHostCount, and canonicalNetworkCidr; invalid batch entries identify error and index.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "cidr": "192.168.1.10/24"
};

// Run the Actor and wait for it to finish
const run = await client.actor("ask4favour/ipv4-cidr-subnet-calculator").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "cidr": "192.168.1.10/24" }

# Run the Actor and wait for it to finish
run = client.actor("ask4favour/ipv4-cidr-subnet-calculator").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "cidr": "192.168.1.10/24"
}' |
apify call ask4favour/ipv4-cidr-subnet-calculator --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,ask4favour/ipv4-cidr-subnet-calculator"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/XudbqkmNLllG2Z2Gb/builds/J9DTeFrRfc5aY1qMb/openapi.json
