Subnet Calculator: CIDR, Masks and Host Ranges for IPv4 and IPv6
By FindMySum · Last reviewed
A subnet calculator turns an IP address and a prefix length into everything you need to configure a network: the network address, the mask, the range of addresses you can hand out, the broadcast address and how many hosts fit. It also splits a block into smaller equal subnets. This article explains the binary arithmetic behind each figure, works through the calculator's default example, and covers the special cases that trip people up: /31 and /32 prefixes, private ranges, and IPv6.
Addresses are just numbers
An IPv4 address is a 32-bit number written as four bytes in decimal, separated by dots. 192.168.1.0 is the bytes 11000000, 10101000, 00000001 and 00000000. An IPv6 address is a 128-bit number written as eight groups of four hexadecimal digits. Everything a subnet calculator does is bitwise arithmetic on those numbers.
A network is described by a prefix: the first n bits are fixed and identify the network, and the remaining bits vary to number the hosts. Classless Inter-Domain Routing (CIDR, RFC 4632) writes this as the address, a slash and n. In 192.168.1.0/24 the first 24 bits are the network and the last 8 bits are free, so the block holds 2^8 = 256 addresses.
The masks
The subnet mask is n one-bits followed by zeros. For /24 that is 255.255.255.0; for /20 it is 255.255.240.0, because the third byte is 11110000. Combining any address with the mask by a bitwise AND clears the host bits and gives the network address. That is why entering 10.20.30.40 with a /13 prefix returns 10.16.0.0/13: the second byte, 20 (00010100), is cut to its first five bits, 00010000, which is 16.
The wildcard mask is the inverse, zeros where the mask has ones: 0.0.0.255 for a /24. Cisco access lists and OSPF network statements use it. OR-ing the network address with the wildcard mask gives the last address in the block.
Network, broadcast and usable hosts
In IPv4 the first address of a block (all host bits zero) names the network and the last (all host bits one) is the directed broadcast address, so neither is given to a device. The usable count for prefixes up to /30 is therefore:
usable hosts = 2^(32 − n) − 2
Two prefixes are exceptions. A /31 has only two addresses, and losing both to network and broadcast would make it useless, so RFC 3021 lets point-to-point links use both with no broadcast. A /32 is a single address, used for loopbacks and host routes. The calculator applies both rules.
Worked example: the default 192.168.1.0/24
The calculator opens with 192.168.1.0 and a /24 prefix, split into /26 subnets.
- Mask: 24 ones, so 255.255.255.0; wildcard 0.0.0.255.
- Network: 192.168.1.0. Broadcast: 192.168.1.255.
- Host range: 192.168.1.1 to 192.168.1.254, which is 254 usable addresses out of 256.
- Type: private, because it falls in 192.168.0.0/16 from RFC 1918.
Splitting into /26 borrows 2 more bits for the network, giving 2^2 = 4 subnets of 2^6 = 64 addresses each, 62 usable:
| Subnet | Usable range | Broadcast |
|---|---|---|
| 192.168.1.0/26 | .1 to .62 | .63 |
| 192.168.1.64/26 | .65 to .126 | .127 |
| 192.168.1.128/26 | .129 to .190 | .191 |
| 192.168.1.192/26 | .193 to .254 | .255 |
Each extra prefix bit doubles the number of subnets and halves their size. The table on the page lists up to 256 subnets and always states the full count.
IPv6 works the same way, with bigger numbers
IPv6 subnetting uses the identical AND-with-mask arithmetic over 128 bits, but RFC 4291 removed broadcast entirely, so every address in a prefix is usable. The calculator shows the network in the short text form from RFC 5952: lower-case hex, leading zeros dropped in each group, and the longest run of two or more zero groups replaced by "::". 2001:0db8:abcd:0012:0000:0000:0000:0000 becomes 2001:db8:abcd:12::.
Address counts get large quickly. A single /64 LAN subnet holds 2^64, about 1.8 × 10^19 addresses, which is why IPv6 planning is about the number of subnets rather than the number of hosts. Splitting the /64 in the calculator into /66s gives four subnets of about 4.6 × 10^18 addresses each, though in practice LANs should stay at /64.
Special-purpose ranges
Not every address is meant for the public internet. The calculator labels each address from the IANA special-purpose registries, including the RFC 1918 private ranges (10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16), carrier-grade NAT space (100.64.0.0/10), loopback (127.0.0.0/8 and ::1), link-local (169.254.0.0/16 and fe80::/10), the documentation ranges used in examples (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24 and 2001:db8::/32), IPv6 unique local addresses (fc00::/7) and multicast. Anything outside those IPv4 blocks is public unicast.
The page also shows the historic class (A to E) of an IPv4 address. Classes stopped mattering for routing when CIDR arrived in 1993, but networking courses and certification exams still ask for them.
More questions
How do I choose a prefix for a given number of hosts?
Add two to the number of hosts you need (for the network and broadcast addresses), round up to the next power of two, and subtract that power's exponent from 32. Forty hosts need 42 addresses, which rounds up to 64 = 2^6, so the prefix is 32 − 6 = /26 with 62 usable addresses. Leave room for growth: renumbering a full subnet later is far more work than starting one size larger.
Can two subnets overlap?
Not if they are allocated from the same address plan, and routers will reject or misroute overlapping networks on directly connected interfaces. Two CIDR blocks either do not overlap at all or one contains the other entirely, because every block starts on a multiple of its own size. A splitting table like the one on this page always produces subnets that sit side by side with no gaps and no overlaps.
What is the difference between a subnet mask and a prefix length?
They carry the same information in two notations. The prefix length counts the leading one-bits; the mask writes those bits out as a dotted-decimal address. /24 and 255.255.255.0 are the same thing, as are /20 and 255.255.240.0. Masks must be contiguous: a mask such as 255.0.255.0 is not valid for subnetting, which is one reason the prefix form has largely replaced it.
Why is a /64 the standard IPv6 subnet size?
IPv6 addresses are split into a 64-bit network part and a 64-bit interface identifier. Stateless address autoconfiguration (SLAAC), privacy addresses and several neighbour discovery features assume that split, so a LAN subnet smaller than /64 breaks them. Internet providers commonly give a home a /56 or /48, which leaves 256 or 65,536 /64 subnets to use inside it.
What is supernetting or route summarisation?
It is subnetting in reverse: combining adjacent blocks into one shorter prefix so a router can advertise a single route. Four networks 10.1.0.0/24 to 10.1.3.0/24 summarise to 10.1.0.0/22, because they share their first 22 bits. Summaries only work when the blocks are contiguous and start on a boundary of the combined size.
Sources
This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.