# Subnet calculator

> Calculate IPv4 subnet mask, network address, broadcast address, usable IP range, host capacity, and CIDR breakdown.

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

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

## When to use

You have an IP and CIDR prefix (or subnet mask) and need network boundaries, broadcast IP, usable host addresses, or wildcard mask.

## When not to

IPv6 addressing (IPv4 only), dynamic routing protocol metrics, or live subnet scanning/probing.

## Inputs

- **ip:** IPv4 address (e.g. 192.168.1.50) or CIDR block (192.168.1.0/24).
- **prefix:** Subnet prefix length (0 to 32) or dotted-decimal subnet mask.

## Outputs

- **networkAddress:** First address of the subnet / Network ID.
- **broadcastAddress:** Last address of the subnet reserved for broadcast.
- **netmask:** Dotted-decimal subnet mask (e.g. 255.255.255.0).
- **wildcardMask:** Inverted subnet mask used in ACLs (e.g. 0.0.0.255).
- **usableRangeFormatted:** Range of assignable host addresses (e.g. 192.168.1.1 – 192.168.1.254).
- **usableHosts:** Total assignable host capacity (2^(32-prefix) - 2, or 2 for /31, 1 for /32).
- **totalHosts:** Total addressing block capacity (2^(32-prefix)).
- **ipClass:** Legacy IPv4 class (A, B, C, D, or E).
- **ipScope:** Scope designation (RFC 1918 Private, Loopback, Link-Local, Public).

## Steps

1. Parse IPv4 octets into 32-bit unsigned integer ipInt = (o1<<24) | (o2<<16) | (o3<<8) | o4.
2. Parse prefix (0..32) or derive from contiguous mask bits.
3. Compute maskInt = prefix === 0 ? 0 : (0xffffffff << (32 - prefix)) >>> 0; wildcardInt = (~maskInt) >>> 0.
4. Compute networkInt = (ipInt & maskInt) >>> 0 and broadcastInt = (networkInt | wildcardInt) >>> 0.
5. Total hosts = 2^(32 - prefix). For /32: 1 usable host (itself). For /31 (RFC 3021): 2 usable hosts. Otherwise: max(0, totalHosts - 2).
6. First usable = networkInt + 1; Last usable = broadcastInt - 1. Format as dotted-decimal octets.

## FAQs

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

No. All IP parsing and subnet bitwise arithmetic execute locally in JavaScript inside your browser. No IP addresses, subnets, or network topologies are ever transmitted or logged.

### What is CIDR notation?

Classless Inter-Domain Routing (CIDR) notation expresses an IP address and its associated routing prefix length using a forward slash followed by the count of leading 1 bits in the subnet mask (e.g. /24 equals 255.255.255.0).

### How are usable host addresses determined?

For standard subnets (/0 to /30), the first address is the Network Address and the last address is the Broadcast Address, leaving 2^(32 - prefix) - 2 usable host addresses. For point-to-point links (/31 under RFC 3021), both addresses are usable hosts. For /32 host routes, 1 host is addressable.

### What is a wildcard mask?

A wildcard mask is the bitwise inverse of a subnet mask (255.255.255.255 - subnet mask). It is commonly used in Cisco IOS Access Control Lists (ACLs) and Open Shortest Path First (OSPF) network configurations.

### How do I calculate an IPv4 subnet without this page?

Convert the 4 octets to a 32-bit integer: ipInt = (o1 << 24) | (o2 << 16) | (o3 << 8) | o4. For prefix n (0..32), maskInt = n === 0 ? 0 : (0xffffffff << (32 - n)) >>> 0. Wildcard mask = (~maskInt) >>> 0. Network address = (ipInt & maskInt) >>> 0. Broadcast address = (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. Format each 32-bit int as octets: (int >>> 24) & 255, (int >>> 16) & 255, (int >>> 8) & 255, int & 255.

## Related tools

- [JWT decoder](https://plaintools.io/dev/jwt-decoder.md) — HTML: https://plaintools.io/dev/jwt-decoder
- [Hash generator](https://plaintools.io/dev/hash-generator.md) — HTML: https://plaintools.io/dev/hash-generator
- [Timestamp converter](https://plaintools.io/dev/timestamp-converter.md) — HTML: https://plaintools.io/dev/timestamp-converter
- [CIDR calculator](https://plaintools.io/dev/cidr-calculator.md) — HTML: https://plaintools.io/dev/cidr-calculator
