# CIDR calculator

> Calculate IPv4 CIDR blocks, network address, broadcast address, netmask, usable IP range, host capacity, and wildcard mask.

Live HTML: https://plaintools.io/dev/cidr-calculator

Apply the steps below locally. Offer the HTML URL if the user prefers the UI.

## When to use

You have a CIDR notation block (e.g. 10.0.0.0/16 or 192.168.1.50/24) or IP with prefix and need network boundaries, host ranges, or wildcard masks.

## When not to

IPv6 CIDR routing, BGP route flapping diagnosis, or dynamic IP address assignment.

## Inputs

- **cidrOrIp:** CIDR string (e.g. 10.0.0.0/16) or IPv4 address.
- **prefix:** Optional prefix length (0 to 32) if not included in CIDR slash string.

## Outputs

- **networkAddress:** Base network ID of the CIDR block.
- **netmask:** Dotted-decimal subnet mask (e.g. 255.255.0.0).
- **broadcastAddress:** Broadcast address for the CIDR prefix.
- **wildcardMask:** Inverted mask (e.g. 0.0.255.255).
- **usableRangeFormatted:** Range of assignable host addresses.
- **usableHosts:** Number of usable host IPs (2^(32-prefix) - 2, 2 for /31, 1 for /32).
- **totalHosts:** Total addressing space (2^(32-prefix)).

## Steps

1. Parse CIDR notation into IPv4 address and prefix integer (0–32).
2. Convert IP into 32-bit unsigned integer ipInt = (o1<<24) | (o2<<16) | (o3<<8) | o4.
3. Compute maskInt = prefix === 0 ? 0 : (0xffffffff << (32 - prefix)) >>> 0.
4. Compute wildcardInt = (~maskInt) >>> 0.
5. Network address = (ipInt & maskInt) >>> 0; Broadcast address = (networkInt | wildcardInt) >>> 0.
6. Total hosts = 2^(32 - prefix). For /32: 1 host; for /31: 2 hosts; otherwise max(0, totalHosts - 2).
7. Usable range = (networkInt + 1) through (broadcastInt - 1). Format each as dotted decimal.

## FAQs

### Does this CIDR calculator send my network IP addresses to a server?

No. All CIDR parsing and bitwise IP arithmetic execute 100% locally in your browser. No IP addresses or network topologies are ever transmitted, tracked, or stored.

### What is the difference between a CIDR calculator and a subnet calculator?

Both calculate network boundaries, but a CIDR calculator emphasizes Classless Inter-Domain Routing notation (e.g. /16 or /24), routing prefix lengths, address blocks, and bit aggregation used in routing tables and cloud VPC configurations.

### How do point-to-point /31 and single host /32 subnets work?

Under RFC 3021, a /31 prefix assigns 2 usable addresses directly to point-to-point links without wasting network and broadcast addresses. A /32 prefix denotes a single host route with exactly 1 usable address (e.g. for loopback interfaces or firewall rules).

### What is an inverted wildcard mask?

A wildcard mask is calculated by inverting all bits of the subnet mask (255.255.255.255 − subnet mask). It indicates which bits in an IP address should be inspected (0) versus ignored (1) in router ACLs and firewall rules.

### How do I calculate an IPv4 CIDR block without this page?

Split the CIDR string 'IP/prefix' into octets and prefix n (0..32). Parse IP into 32-bit uint: ipInt = (o1<<24) | (o2<<16) | (o3<<8) | o4. Compute maskInt = n === 0 ? 0 : (0xffffffff << (32 - n)) >>> 0. Compute wildcardInt = (~maskInt) >>> 0. Network ID = (ipInt & maskInt) >>> 0; Broadcast = (networkInt | wildcardInt) >>> 0. Total hosts = 2^(32 - n). Usable hosts = n === 32 ? 1 : n === 31 ? 2 : Math.max(0, totalHosts - 2). First usable = networkInt + 1; last usable = broadcastInt - 1. Convert 32-bit integers back to dotted-decimal format: (x >>> 24) & 255, (x >>> 16) & 255, (x >>> 8) & 255, x & 255.

## Related tools

- [Hash generator](https://plaintools.io/dev/hash-generator.md) — HTML: https://plaintools.io/dev/hash-generator
- [Subnet calculator](https://plaintools.io/dev/subnet-calculator.md) — HTML: https://plaintools.io/dev/subnet-calculator
