# Subnet calculator (IPv4 and IPv6 CIDR)

> Find the network address, broadcast, usable host range and host count of any IPv4 or IPv6 CIDR block, with netmask, wildcard and equal subnets.

Interactive version: https://www.calcopenly.com/programming/subnet-cidr-calculator
Subject: Programming and tech calculators

A prefix length p keeps the first p bits of an address as the network and leaves the rest to number hosts. The calculator ANDs the address with the netmask to find the network address, ORs that with the wildcard mask (the inverted netmask) to find the last address, and counts 2^(32 − p) addresses for IPv4 or 2^(128 − p) for IPv6.

Engineers use it to plan VLANs, firewall rules and cloud VPC ranges. The default, 192.168.10.77/26, belongs to 192.168.10.64/26: 64 addresses, 62 of them usable from .65 to .126, with .127 as the broadcast. Splitting it 4 ways gives four /28 subnets of 16 addresses.

IPv4 counts leave out the network and broadcast addresses except on /31 point-to-point links (RFC 3021) and /32 host routes. IPv6 has no broadcast, so only the subnet-router anycast address is left out. Splits are always into a power of two equal subnets; for a VLSM plan, split one of the results again.

## Inputs

- **Address and prefix**: IPv4 as 10.1.2.3/24 or with a netmask (10.1.2.3 255.255.255.0); IPv6 as 2001:db8::1/64.
- **Split into this many subnets**: Rounded up to a power of two; 1 keeps the network whole.

## Results

- Network — main result
- Netmask
- Wildcard mask
- Prefix length
- First usable address
- Last usable address
- Broadcast address
- Usable addresses
- Total addresses
- Historical class
- Address type
- Full form
- Short form (RFC 5952)
- Prefix of each subnet
- Addresses in each subnet

## Formula

$$
\begin{aligned}\text{network} &= \text{address} \land \text{mask} \\ \text{last} &= \text{network} \lor \lnot\text{mask} \\ \text{hosts} &= 2^{32-p} - 2\end{aligned}
$$

## Worked examples

### Host in a /26

- Address and prefix: 192.168.10.77/26
- Split into this many subnets: 1
- **Network: 192.168.10.64/26**
- **Netmask: 255.255.255.192**
- **Wildcard mask: 0.0.0.63**
- **Broadcast address: 192.168.10.127**
- **First usable address: 192.168.10.65**
- **Last usable address: 192.168.10.126**
- **Usable addresses: 62**
- **Total addresses: 64**
- **Historical class: C**
- **Address type: Private (RFC 1918)**
- Checked against: Python 3.8 ipaddress.ip_interface('192.168.10.77/26').network, .netmask, .hostmask, .broadcast_address, list(hosts())

### Point-to-point /31 (edge)

- Address and prefix: 10.0.0.0/31
- Split into this many subnets: 1
- **First usable address: 10.0.0.0**
- **Last usable address: 10.0.0.1**
- **Usable addresses: 2**
- **Total addresses: 2**
- Checked against: RFC 3021 §2; Python 3.8 list(ip_network('10.0.0.0/31').hosts()) = [10.0.0.0, 10.0.0.1]

### Single host /32 (edge)

- Address and prefix: 203.0.113.5/32
- Split into this many subnets: 1
- **Network: 203.0.113.5/32**
- **First usable address: 203.0.113.5**
- **Last usable address: 203.0.113.5**
- **Usable addresses: 1**
- **Address type: Documentation, TEST-NET-3 (RFC 5737)**
- Checked against: Python 3.8 list(ip_network('203.0.113.5/32').hosts()) = [203.0.113.5]; RFC 5737 §3

### Netmask instead of a prefix

- Address and prefix: 172.16.5.4 255.255.240.0
- Split into this many subnets: 1
- **Network: 172.16.0.0/20**
- **Prefix length: 20**
- **Broadcast address: 172.16.15.255**
- **Total addresses: 4,096**
- **Historical class: B**
- Checked against: Python 3.8 ip_interface('172.16.5.4/255.255.240.0').network = 172.16.0.0/20, num_addresses = 4096

### Split a /24 into 3 (rounded up to 4)

- Address and prefix: 192.168.1.0/24
- Split into this many subnets: 3
- **Prefix of each subnet: 26**
- **Addresses in each subnet: 64**
- Checked against: Python 3.8 list(ip_network('192.168.1.0/24').subnets(prefixlen_diff=2)) gives four /26 networks of 64 addresses

### Carrier-grade NAT range

- Address and prefix: 100.64.1.1/10
- Split into this many subnets: 1
- **Network: 100.64.0.0/10**
- **Usable addresses: 4,194,302**
- **Address type: Shared address space for carrier-grade NAT (RFC 6598)**
- Checked against: Python 3.8 ip_network('100.64.0.0/10').num_addresses − 2 = 4194302; RFC 6598 §7

## Questions

### How many usable hosts are in a /24 subnet?

A /24 has 256 addresses and 254 usable hosts, because the all-zeros address names the network and the all-ones address is the broadcast. The IPv4 rule is 2^(32 − prefix) − 2: a /25 gives 126, a /26 62, a /27 30, a /28 14, a /29 6 and a /30 2. The exceptions are /31, where RFC 3021 lets a point-to-point link use both addresses, and /32, a single host.

### What is the difference between a subnet mask and CIDR notation?

They say the same thing in two ways. CIDR notation writes the number of network bits after a slash, as in /26; a subnet mask writes those bits as a dotted address with that many leading ones, so /26 is 255.255.255.192 and /20 is 255.255.240.0. CIDR, introduced in 1993 and now defined in RFC 4632, replaced the fixed class A, B and C boundaries, so any prefix from /0 to /32 is valid.

### What is a wildcard mask?

A wildcard mask is the subnet mask with every bit inverted, so 255.255.255.192 becomes 0.0.0.63. Cisco IOS access lists and OSPF network statements use it: a 0 bit must match and a 1 bit is ignored. To get it, subtract each octet of the netmask from 255. For a /26 the last octet is 63, one less than the block's 64 addresses.

### Why do AWS and Azure subnets have 5 fewer usable addresses?

Both clouds reserve 5 addresses in every subnet: the network address, the next three (for the router and DNS, or held for future use) and the last address. A /24 in an AWS VPC or Azure virtual network therefore has 251 assignable addresses instead of the 254 shown here. The smallest subnet AWS allows is a /28, which leaves 11; Azure's smallest is a /29, which leaves 3.

### How many addresses are in an IPv6 /64?

A /64 holds 2^64 = 18,446,744,073,709,551,616 addresses. It is the standard size for one IPv6 LAN because RFC 4291 requires 64-bit interface identifiers for most unicast addresses, and stateless autoconfiguration (SLAAC) builds addresses from them. A /48 contains 65,536 of those /64 subnets, and a /56 contains 256.

### How accurate is the subnet calculator?

Accuracy depends on your inputs and the method's assumptions. Decimal arithmetic uses 50 significant digits, but estimates, numerical methods and source data can be less precise; the displayed rounding does not remove those limits. It is checked against 7 worked examples whose answers come from independent sources; for example, “Host in a /26” is checked against Python 3.8 ipaddress.ip_interface('192.168.10.77/26').network, .netmask, .hostmask, .broadcast_address, list(hosts()).

### Where does the method come from?

RFC 4632 — Classless Inter-domain Routing (CIDR); RFC 3021 — Using 31-bit prefixes on IPv4 point-to-point links; RFC 1918 — Address allocation for private internets; RFC 4291 — IPv6 addressing architecture; RFC 5952 — IPv6 text representation; IANA IPv4 and IPv6 special-purpose address registries (RFC 6890).

## Sources

- [RFC 4632 — Classless Inter-domain Routing (CIDR)](https://www.rfc-editor.org/rfc/rfc4632)
- [RFC 3021 — Using 31-bit prefixes on IPv4 point-to-point links](https://www.rfc-editor.org/rfc/rfc3021)
- [RFC 1918 — Address allocation for private internets](https://www.rfc-editor.org/rfc/rfc1918)
- [RFC 4291 — IPv6 addressing architecture; RFC 5952 — IPv6 text representation](https://www.rfc-editor.org/rfc/rfc5952)
- [IANA IPv4 and IPv6 special-purpose address registries (RFC 6890)](https://www.iana.org/assignments/iana-ipv4-special-registry/)
