A subnet calculator takes an IP address and a prefix length or subnet mask, and works out the network it belongs to: the network and broadcast addresses, the range of usable host addresses, the masks and the number of hosts. Type an address like 192.168.1.10/24 above to see all of it, along with every address in binary. Below is how IPv4 subnetting works bit by bit, with a cheat sheet of the common subnet sizes.
IP addresses in binary
An IPv4 address is a 32-bit number. It's written as four decimal numbers from 0 to 255, called octets, because each one is 8 bits. 192.168.1.10 in binary is 11000000.10101000.00000001.00001010. There are 2³², or 4,294,967,296, possible IPv4 addresses. Subnetting splits that 32-bit number into two parts: the first bits identify the network, and the rest identify a host on that network. The decimal to binary converter shows how each octet becomes 8 bits.
Subnet masks and CIDR notation
A subnet mask marks which bits belong to the network. It's a run of 1 bits followed by 0 bits, written like an address. 255.255.255.0 is twenty-four 1s followed by eight 0s, so the first 24 bits are the network. CIDR notation writes the same thing as a slash and the number of 1 bits: /24. The mask's 1s must always come first, which is why only 33 masks exist, from /0 to /32, and why a mask like 255.0.255.0 isn't valid.
Finding the network and broadcast address
The network address is the IP address with every host bit set to 0. In binary, that's a bitwise AND of the address and the mask: a bit stays 1 only where both have a 1. The broadcast address is the opposite end, with every host bit set to 1. For 192.168.0.130/26, the last octet 130 is 10000010 and the mask's last octet 192 is 11000000. ANDing them gives 10000000, or 128, so the network is 192.168.0.128. Setting the six host bits to 1 gives 10111111, or 191, so the broadcast is 192.168.0.191.
How many hosts a subnet has
With n host bits, a subnet has 2ⁿ addresses. Two of them are reserved, the network address and the broadcast address, so the usable host count is 2ⁿ − 2. A /24 has 8 host bits: 256 addresses and 254 hosts. A /26 has 6: 64 addresses and 62 hosts. There are two exceptions. A /31 has only 2 addresses, and point-to-point links use both as hosts (RFC 3021). A /32 is a single address, used for one host or a route to it.
Subnet mask cheat sheet
| CIDR | Subnet mask | Addresses | Usable hosts |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 |
| /16 | 255.255.0.0 | 65,536 | 65,534 |
| /20 | 255.255.240.0 | 4,096 | 4,094 |
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 2 |
| /31 | 255.255.255.254 | 2 | 2 |
| /32 | 255.255.255.255 | 1 | 1 |
Splitting a network into subnets
Each extra bit of prefix halves the subnet. Borrowing 2 bits from a /24 turns it into four /26 networks of 62 hosts each:
192.168.1.0/26: hosts 192.168.1.1 – 192.168.1.62192.168.1.64/26: hosts 192.168.1.65 – 192.168.1.126192.168.1.128/26: hosts 192.168.1.129 – 192.168.1.190192.168.1.192/26: hosts 192.168.1.193 – 192.168.1.254
Notice the networks step by 64, which is 2⁶, the number of addresses in each one. Network addresses always fall on a multiple of the subnet size, which makes it easy to check a subnet by hand.
Private and special addresses
Three ranges are reserved for private networks and never appear on the public internet: 10.0.0.0/8, 172.16.0.0/12 (172.16.0.0 to 172.31.255.255) and 192.168.0.0/16. Home routers almost always use 192.168. Other special ranges include loopback 127.0.0.0/8, link-local 169.254.0.0/16, which a device picks for itself when no DHCP server answers, and 100.64.0.0/10 for carrier-grade NAT. The calculator labels the type of every address you enter.
Wildcard masks
A wildcard mask is the subnet mask with every bit flipped, so /24 gives 0.0.0.255. Cisco access lists and OSPF use wildcard masks to say which bits of an address can vary. The calculator shows the wildcard for every prefix, ready to copy.
Input tips and limits
- You can type a dotted mask instead of a prefix, as in
192.168.1.10 255.255.255.0. - Any address in a subnet gives the same network, so you don't need to start from the network address.
- This calculator works with IPv4. IPv6 addresses are 128 bits and are usually split into /64 subnets.
To size a subnet in your head, subtract the prefix from 32 to get the host bits, then take 2 to that power and subtract 2. A /27 has 5 host bits, so it holds 30 hosts.