ForHosting KIT · Developer Utilities

Prefix length to address count calculator

This prefix length to address count calculator shows exactly how many IPv4 or IPv6 addresses belong to a subnet when you know its CIDR prefix.

● BetaFree · in your browser
Use it from WebAPIEmailTelegramApp soon

Select the address family and enter the number after the slash, such as 24 for IPv4 /24 or 64 for IPv6 /64. The result identifies the address width, host bits, power-of-two formula, exact address count, and a compact reference table. It counts every address in the mathematical block without applying network, broadcast, provider, or operational reservations.

Turn a prefix length into an exact address count

CIDR notation divides an IP address into network bits and host bits. The prefix length is the number after the slash and states how many leading bits identify the network. IPv4 addresses contain 32 bits, while IPv6 addresses contain 128 bits. Subtract the prefix length from that width to obtain the host bits, then raise two to that number. An IPv4 /24 leaves eight host bits, so its block contains 2^8, or 256, total addresses. An IPv6 /64 leaves 64 host bits and contains exactly 18,446,744,073,709,551,616 addresses. This calculator performs that operation with exact integer arithmetic and returns the count as a decimal string, so large IPv6 results are never rounded by floating-point limits. Enter the prefix length itself rather than a full address or CIDR block. Choose the correct family because the same prefix has a radically different meaning across address widths: IPv4 /24 leaves eight host bits, whereas IPv6 /24 leaves 104. The formula field makes the calculation visible instead of presenting an unexplained result.

Distinguish total addresses from usable hosts

The returned address count is the complete mathematical size of the subnet, not an estimate of how many devices you can deploy. For conventional IPv4 networks, the network identifier and broadcast address may not be assignable to ordinary interfaces, and platforms can reserve additional addresses for gateways or managed services. Point-to-point /31 networks and /32 host routes also have operational rules that do not fit a universal subtract-two shortcut. IPv6 has no broadcast address, and its allocation and subnetting practices differ substantially from IPv4. For these reasons, this capability applies only the stable CIDR formula and does not label any address usable or reserved. That separation makes the answer appropriate for address-space inventory, prefix comparison, allocation documentation, and software validation. If you need endpoint capacity, apply the policies of the actual network or provider after obtaining the total. A /0 represents the entire address-family space, while /32 for IPv4 or /128 for IPv6 represents one address. Every increase of one in the prefix halves the address count because it converts one host bit into a network bit.

Use the reference table for planning and verification

The response includes a reference table of common prefixes for the selected address family, and it inserts the requested prefix when that value is not already among them. Each row gives the prefix length, remaining host bits, and exact total address count. This is useful when comparing adjacent subnet sizes, reviewing an allocation plan, or checking that code and documentation agree. For example, the IPv4 rows make it easy to see that /24 contains 256 addresses, /25 contains 128, and /26 contains 64. The IPv6 table includes frequently discussed boundaries such as /32, /48, /56, /64, /96, and /128 while preserving their full decimal counts. Treat the table as a mathematical reference rather than a recommendation about which prefix should be assigned. Routing policy, registry guidance, cloud limits, local security boundaries, and expected growth all affect a real allocation decision. API calls cost $0.002 per request, and the deterministic algorithm performs no network lookup. Identical inputs therefore produce identical output, making the capability safe for tests, infrastructure pipelines, documentation generators, and educational tools that need repeatable prefix calculations.

Compare proposed subnet sizes

Calculate exact totals for candidate IPv4 or IPv6 prefixes before recording an address allocation plan.

Validate infrastructure input

Confirm that a configured prefix implies the address count expected by deployment or inventory automation.

Build networking reference material

Generate exact power-of-two counts and a compact table without risking rounded IPv6 values.

How is the address count calculated?

Subtract the prefix length from 32 for IPv4 or 128 for IPv6, then calculate two raised to the remaining host bits.

Why is the address count returned as a string?

A decimal string preserves exact IPv6 counts that exceed the safe integer range of common JSON and JavaScript number implementations.

Does the result show usable host addresses?

No. It reports every address in the mathematical subnet and does not subtract network, broadcast, provider, or policy reservations.

Can I enter a full CIDR address?

No. Supply the address family and the integer prefix length only, such as ipv4 with 24 or ipv6 with 64.

What are the valid prefix ranges?

IPv4 accepts prefix lengths from 0 through 32, and IPv6 accepts prefix lengths from 0 through 128.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/dev/cidr-count-addresses

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/dev/cidr-count-addresses \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"family":"ipv4","prefix_length":24}'
{
  "family": "ipv4",
  "prefix_length": 24
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "dev.cidr_count_addresses",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Read the full KIT documentation →