How subnetting works
An IPv4 address is 32 bits. The prefix length says how many of those bits, counted from the left, identify the network. The rest identify a device on that network. A /26 fixes 26 bits and leaves 6 for hosts, which gives 26 = 64 addresses.
Formula
- Network
- address AND mask
- Broadcast
- network OR wildcard
- Wildcard
- NOT mask
- Usable hosts
- 2(32 − prefix) − 2
The first address names the network and the last is broadcast, so neither goes to a device. /31 point-to-point links (RFC 3021) and /32 single hosts are the exceptions: a /31 has two usable addresses and no broadcast, a /32 is one address.
When you give a host count instead of a size, the calculator picks the smallest block whose usable addresses cover it: 50 hosts need a /26, which has 62. A /27 would only hold 30. It never suggests a /31 or /32 for a host count; use those directly for a point-to-point link or a single address.
Worked example
A device at 192.168.1.130 with a /26 mask (255.255.255.192). The last octet, 130, is 10000010 in binary. Keep the first 2 bits (the network part) and zero the other 6: 10000000 = 128. So the network is 192.168.1.128, the broadcast is 128 + 63 = 191, and devices use .129 through .190: 62 addresses.
Sizes by prefix
Each prefix from /8 to /32 has its own page with the mask in binary and hex, how many fit in the private ranges, example networks and a worked example.
| Prefix | Mask | Addresses | Usable |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 |
| /9 | 255.128.0.0 | 8,388,608 | 8,388,606 |
| /10 | 255.192.0.0 | 4,194,304 | 4,194,302 |
| /11 | 255.224.0.0 | 2,097,152 | 2,097,150 |
| /12 | 255.240.0.0 | 1,048,576 | 1,048,574 |
| /13 | 255.248.0.0 | 524,288 | 524,286 |
| /14 | 255.252.0.0 | 262,144 | 262,142 |
| /15 | 255.254.0.0 | 131,072 | 131,070 |
| /16 | 255.255.0.0 | 65,536 | 65,534 |
| /17 | 255.255.128.0 | 32,768 | 32,766 |
| /18 | 255.255.192.0 | 16,384 | 16,382 |
| /19 | 255.255.224.0 | 8,192 | 8,190 |
| /20 | 255.255.240.0 | 4,096 | 4,094 |
| /21 | 255.255.248.0 | 2,048 | 2,046 |
| /22 | 255.255.252.0 | 1,024 | 1,022 |
| /23 | 255.255.254.0 | 512 | 510 |
| /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 |
IPv6
Type an IPv6 address with its prefix length, like 2001:db8:abcd:12::7/64. The idea is the same: the prefix length fixes the leftmost bits. An IPv6 address is 128 bits, written as eight groups of four hex digits; the result uses the standard short form (RFC 5952): lower case, leading zeros dropped, and :: for the longest run of zero groups.
Three things differ from IPv4. There is no broadcast address, so the result shows the first and last address and the total instead of usable hosts. There are no dotted masks, only prefix lengths. And networks have a standard size: a LAN gets a /64, because interface identifiers are 64 bits and stateless autoconfiguration (SLAAC) only works on a /64. A /48 holds 65,536 (2^16) of them and a /56 holds 256; end sites are usually given one or the other (RFC 6177). Links between two routers can use a /127 (RFC 6164).
For 2001:db8:abcd:12::7/64: the network is 2001:db8:abcd:12::/64, the last address is 2001:db8:abcd:12:ffff:ffff:ffff:ffff, and the block holds 18,446,744,073,709,551,616 (2^64) addresses. It sits inside 2001:db8::/32, the prefix set aside for documentation.
IPv6 prefix pages, with what each size holds and the RFC rules for it:
Special address ranges
Some blocks are set aside for private networks, loopback, documentation and other uses, and are not routed on the public internet. The result tells you when your subnet falls in, or contains, one of these. The lists follow the IANA IPv4 and IPv6 Special-Purpose Address registries, plus multicast, IPv4's reserved 240.0.0.0/4 and IPv6's deprecated site-local range. IPv6 addresses outside these blocks are global unicast if they start with 2 or 3 (2000::/3); the rest is held in reserve by the IETF.
| Block | Use | Defined in |
|---|---|---|
| 0.0.0.0/8 | "This network" | RFC 791 §3.2 |
| 0.0.0.0/32 | "This host on this network" | RFC 1122 §3.2.1.3 |
| 10.0.0.0/8 | Private-Use | RFC 1918 |
| 100.64.0.0/10 | Shared Address Space | RFC 6598 |
| 127.0.0.0/8 | Loopback | RFC 1122 §3.2.1.3 |
| 169.254.0.0/16 | Link Local | RFC 3927 |
| 172.16.0.0/12 | Private-Use | RFC 1918 |
| 192.0.0.0/24 | IETF Protocol Assignments | RFC 6890 §2.1 |
| 192.0.0.0/29 | IPv4 Service Continuity Prefix | RFC 7335 |
| 192.0.0.8/32 | IPv4 dummy address | RFC 7600 |
| 192.0.0.9/32 | Port Control Protocol Anycast | RFC 7723 |
| 192.0.0.10/32 | Traversal Using Relays around NAT Anycast | RFC 8155 |
| 192.0.0.170/32 | NAT64/DNS64 Discovery | RFC 8880; RFC 7050 §2.2 |
| 192.0.0.171/32 | NAT64/DNS64 Discovery | RFC 8880; RFC 7050 §2.2 |
| 192.0.2.0/24 | Documentation (TEST-NET-1) | RFC 5737 |
| 192.31.196.0/24 | AS112-v4 | RFC 7535 |
| 192.52.193.0/24 | AMT | RFC 7450 |
| 192.88.99.0/24 | Deprecated (6to4 Relay Anycast) | RFC 7526 |
| 192.88.99.2/32 | 6a44-relay anycast address | RFC 6751 |
| 192.168.0.0/16 | Private-Use | RFC 1918 |
| 192.175.48.0/24 | Direct Delegation AS112 Service | RFC 7534 |
| 198.18.0.0/15 | Benchmarking | RFC 2544 |
| 198.51.100.0/24 | Documentation (TEST-NET-2) | RFC 5737 |
| 203.0.113.0/24 | Documentation (TEST-NET-3) | RFC 5737 |
| 224.0.0.0/4 | Multicast | RFC 5771 |
| 240.0.0.0/4 | Reserved | RFC 1112 §4 |
| 255.255.255.255/32 | Limited Broadcast | RFC 8190; RFC 919 §7 |
| Block | Use | Defined in |
|---|---|---|
| ::/128 | Unspecified Address | RFC 4291 |
| ::1/128 | Loopback Address | RFC 4291 |
| ::ffff:0:0/96 | IPv4-mapped Address | RFC 4291 |
| 64:ff9b::/96 | IPv4-IPv6 Translat. | RFC 6052 |
| 64:ff9b:1::/48 | IPv4-IPv6 Translat. | RFC 8215 |
| 100::/64 | Discard-Only Address Block | RFC 6666 |
| 100:0:0:1::/64 | Dummy IPv6 Prefix | RFC 9780 |
| 2001::/23 | IETF Protocol Assignments | RFC 2928 |
| 2001::/32 | TEREDO | RFC 4380; RFC 8190 |
| 2001:1::1/128 | Port Control Protocol Anycast | RFC 7723 |
| 2001:1::2/128 | Traversal Using Relays around NAT Anycast | RFC 8155 |
| 2001:1::3/128 | DNS-SD Service Registration Protocol Anycast | RFC 9665 |
| 2001:2::/48 | Benchmarking | RFC 5180; erratum 1752 |
| 2001:3::/32 | AMT | RFC 7450 |
| 2001:4:112::/48 | AS112-v6 | RFC 7535 |
| 2001:10::/28 | Deprecated (previously ORCHID) | RFC 4843 |
| 2001:20::/28 | ORCHIDv2 | RFC 7343 |
| 2001:30::/28 | Drone Remote ID Protocol Entity Tags (DETs) Prefix | RFC 9374 |
| 2001:db8::/32 | Documentation | RFC 3849 |
| 2002::/16 | 6to4 | RFC 3056 |
| 2620:4f:8000::/48 | Direct Delegation AS112 Service | RFC 7534 |
| 3fff::/20 | Documentation | RFC 9637 |
| 5f00::/16 | Segment Routing (SRv6) SIDs | RFC 9602 |
| fc00::/7 | Unique-Local | RFC 4193; RFC 8190 |
| fe80::/10 | Link-Local Unicast | RFC 4291 |
| fec0::/10 | Site-Local (deprecated) | RFC 3879 |
| ff00::/8 | Multicast | RFC 4291 |
References
- RFC 4632, Classless Inter-domain Routing (CIDR): prefix notation and block sizes.
- RFC 950, Internet Standard Subnetting Procedure; RFC 1878, Variable Length Subnet Table for IPv4.
- RFC 1812, Requirements for IP Version 4 Routers: subnet masks must be contiguous.
- RFC 3021, Using 31-Bit Prefixes on IPv4 Point-to-Point Links.
- RFC 1918, Address Allocation for Private Internets.
- RFC 4291, IP Version 6 Addressing Architecture; RFC 5952, A Recommendation for IPv6 Address Text Representation.
- RFC 6164, Using 127-Bit IPv6 Prefixes on Inter-Router Links; RFC 7421, Analysis of the 64-bit Boundary in IPv6 Addressing.
- IANA IPv4 and IPv6 Special-Purpose Address registries (RFC 6890) and the IANA IPv6 Address Space registry.