Understanding the IPv4 subnet calculator — concept and principle
An IPv4 subnet calculator takes one address and a prefix length (the "/n" in CIDR notation) and tells you which network that address belongs to: the network address, subnet mask, wildcard mask, broadcast address, the range of addresses you can assign to devices, and how many there are. It is used when planning address ranges, writing firewall rules, configuring DHCP scopes and troubleshooting connectivity.
How it is calculated
An IPv4 address is a 32-bit number written as four decimal octets. The prefix length n says how many leading bits identify the network.
- Subnet mask: n ones followed by 32 − n zeros, e.g. /26 = 255.255.255.192.
- Network address: IP AND mask (bitwise), which clears the host bits.
- Wildcard mask: NOT mask, i.e. 255.255.255.255 − mask.
- Broadcast address: network OR wildcard, which sets every host bit to 1.
- Usable hosts: 2^(32 − n) − 2 for n ≤ 30. On a /31 point-to-point link both addresses are usable (RFC 3021); a /32 is a single host.
- Class · type: the historical class from the first octet (A 0–127, B 128–191, C 192–223, D multicast, E reserved), then private (RFC 1918), loopback, link-local, CGNAT (RFC 6598), other special-purpose ranges, or public.
The principle
Routers forward traffic by comparing only the network bits. Every address that shares the same first n bits is "on-link" and reachable without a router. The all-zeros host pattern names the network itself and the all-ones pattern is the directed broadcast, so in a normal subnet those two are reserved, which is where the "− 2" comes from. Subnet sizes are therefore powers of two, and each subnet starts on a multiple of its size.
Worked example
- Inputs: IP 192.168.10.37, prefix /26.
- Mask: 26 ones = 255.255.255.192 (last octet 11000000).
- Last octet of the IP: 37 = 00100101. 37 AND 192 = 0, so the network is 192.168.10.0/26.
- Wildcard: 0.0.0.63. Broadcast: 0 OR 63 = 192.168.10.63.
- Usable range: 192.168.10.1 – 192.168.10.62, which is 2^6 − 2 = 62 hosts.
- First octet 192 is class C, and 192.168.0.0/16 is private, so the row reads C · private (RFC 1918).
How to read the result
Two hosts talk directly only if they compute the same network address. A /24 gives 254 hosts, /26 gives 62, /28 gives 14 and /30 gives 2. The gateway must be a usable address, usually the first or last.
Common mistakes
- Assigning the network or broadcast address to a device.
- Confusing the subnet mask with the wildcard mask.
- Assuming subnets can start anywhere; a /26 can only start at .0, .64, .128 or .192.
Frequently asked questions
Why does a /26 have 64 addresses but only 62 hosts?
The first address identifies the network and the last is the broadcast address, so neither is assigned to an interface.
Are classes A, B and C still used?
Not for routing. Since CIDR any prefix length is allowed; class names survive as shorthand for /8, /16 and /24.
Sources: IETF RFC 4632, Classless Inter-domain Routing (CIDR) · IETF RFC 1918, Address Allocation for Private Internets · IETF RFC 3021, Using 31-Bit Prefixes on IPv4 Point-to-Point Links