Subnet Mask Cheat Sheet
Subnet mask table for every IPv4 prefix from /0 to /32: dotted mask, wildcard, total and usable hosts, with /31 counted as 2 (RFC 3021) and /32 as 1. How it works
Use the Subnet Mask Cheat Sheet
| CIDR | Subnet Mask | Wildcard | Total Addresses | Usable Hosts | Network Bits | Copy |
|---|---|---|---|---|---|---|
| /0 | 0.0.0.0 | 255.255.255.255 | 4,294,967,296 | 4,294,967,294 | 0 | |
| /1 | 128.0.0.0 | 127.255.255.255 | 2,147,483,648 | 2,147,483,646 | 1 | |
| /2 | 192.0.0.0 | 63.255.255.255 | 1,073,741,824 | 1,073,741,822 | 2 | |
| /3 | 224.0.0.0 | 31.255.255.255 | 536,870,912 | 536,870,910 | 3 | |
| /4 | 240.0.0.0 | 15.255.255.255 | 268,435,456 | 268,435,454 | 4 | |
| /5 | 248.0.0.0 | 7.255.255.255 | 134,217,728 | 134,217,726 | 5 | |
| /6 | 252.0.0.0 | 3.255.255.255 | 67,108,864 | 67,108,862 | 6 | |
| /7 | 254.0.0.0 | 1.255.255.255 | 33,554,432 | 33,554,430 | 7 | |
| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,216 | 16,777,214 | 8 | |
| /9 | 255.128.0.0 | 0.127.255.255 | 8,388,608 | 8,388,606 | 9 | |
| /10 | 255.192.0.0 | 0.63.255.255 | 4,194,304 | 4,194,302 | 10 | |
| /11 | 255.224.0.0 | 0.31.255.255 | 2,097,152 | 2,097,150 | 11 | |
| /12 | 255.240.0.0 | 0.15.255.255 | 1,048,576 | 1,048,574 | 12 | |
| /13 | 255.248.0.0 | 0.7.255.255 | 524,288 | 524,286 | 13 | |
| /14 | 255.252.0.0 | 0.3.255.255 | 262,144 | 262,142 | 14 | |
| /15 | 255.254.0.0 | 0.1.255.255 | 131,072 | 131,070 | 15 | |
| /16 | 255.255.0.0 | 0.0.255.255 | 65,536 | 65,534 | 16 | |
| /17 | 255.255.128.0 | 0.0.127.255 | 32,768 | 32,766 | 17 | |
| /18 | 255.255.192.0 | 0.0.63.255 | 16,384 | 16,382 | 18 | |
| /19 | 255.255.224.0 | 0.0.31.255 | 8,192 | 8,190 | 19 | |
| /20 | 255.255.240.0 | 0.0.15.255 | 4,096 | 4,094 | 20 | |
| /21 | 255.255.248.0 | 0.0.7.255 | 2,048 | 2,046 | 21 | |
| /22 | 255.255.252.0 | 0.0.3.255 | 1,024 | 1,022 | 22 | |
| /23 | 255.255.254.0 | 0.0.1.255 | 512 | 510 | 23 | |
| /24 | 255.255.255.0 | 0.0.0.255 | 256 | 254 | 24 | |
| /25 | 255.255.255.128 | 0.0.0.127 | 128 | 126 | 25 | |
| /26 | 255.255.255.192 | 0.0.0.63 | 64 | 62 | 26 | |
| /27 | 255.255.255.224 | 0.0.0.31 | 32 | 30 | 27 | |
| /28 | 255.255.255.240 | 0.0.0.15 | 16 | 14 | 28 | |
| /29 | 255.255.255.248 | 0.0.0.7 | 8 | 6 | 29 | |
| /30 | 255.255.255.252 | 0.0.0.3 | 4 | 2 | 30 | |
| /31 | 255.255.255.254 | 0.0.0.1 | 2 | 2 | 31 | |
| /32 | 255.255.255.255 | 0.0.0.0 | 1 | 1 | 32 |
Which mask fits my hosts?
Rule: pick the smallest block (the longest prefix) whose usable hosts are at least the number you need.
| Hosts needed (up to) | Host Bits | CIDR | Subnet Mask |
|---|---|---|---|
| 2 | 1 | /31 | 255.255.255.254 |
| 6 | 3 | /29 | 255.255.255.248 |
| 14 | 4 | /28 | 255.255.255.240 |
| 30 | 5 | /27 | 255.255.255.224 |
| 62 | 6 | /26 | 255.255.255.192 |
| 126 | 7 | /25 | 255.255.255.128 |
| 254 | 8 | /24 | 255.255.255.0 |
| 510 | 9 | /23 | 255.255.254.0 |
| 1,022 | 10 | /22 | 255.255.252.0 |
| 2,046 | 11 | /21 | 255.255.248.0 |
| 4,094 | 12 | /20 | 255.255.240.0 |
| 8,190 | 13 | /19 | 255.255.224.0 |
| 16,382 | 14 | /18 | 255.255.192.0 |
| 32,766 | 15 | /17 | 255.255.128.0 |
| 65,534 | 16 | /16 | 255.255.0.0 |
A /31 (2 hosts) has no network or broadcast address (RFC 3021). Equipment that reserves those two addresses needs a /30 for 2 hosts.
Usable hosts are the total minus the network and broadcast addresses, except /31 (2: both addresses are hosts on a point-to-point link, RFC 3021) and /32 (1: a single host address).
About the Subnet Mask Cheat Sheet
A /24 is the mask 255.255.255.0, with the wildcard 0.0.0.255, 256 addresses and 254 usable hosts. The table covers every IPv4 prefix from /0 to /32 with its dotted mask, wildcard, total addresses and usable hosts. A /31 counts 2 usable hosts (RFC 3021) and a /32 counts 1, because the usual total minus 2 does not fit them. Type a host count under Which mask fits my hosts? and it names the smallest mask: 26 hosts need /27 (255.255.255.224, 30 usable).
The eight mask octet values and the prefixes that end in them
| Mask octet | 1 bits in the octet | Wildcard octet | Prefixes |
|---|---|---|---|
| 128 | 1 | 127 | /1, /9, /17, /25 |
| 192 | 2 | 63 | /2, /10, /18, /26 |
| 224 | 3 | 31 | /3, /11, /19, /27 |
| 240 | 4 | 15 | /4, /12, /20, /28 |
| 248 | 5 | 7 | /5, /13, /21, /29 |
| 252 | 6 | 3 | /6, /14, /22, /30 |
| 254 | 7 | 1 | /7, /15, /23, /31 |
| 255 | 8 | 0 | /8, /16, /24, /32 |
A valid mask is a run of 255s, then one of these values, then 0s. 192 in the fourth octet is /26 (255.255.255.192), in the third /18 (255.255.192.0). Each wildcard octet is 255 minus the mask octet.
Hosts needed and the smallest mask that holds them
| Hosts needed (up to) | Host bits | CIDR | Subnet mask |
|---|---|---|---|
| 2 | 1 | /31 | 255.255.255.254 |
| 6 | 3 | /29 | 255.255.255.248 |
| 14 | 4 | /28 | 255.255.255.240 |
| 30 | 5 | /27 | 255.255.255.224 |
| 62 | 6 | /26 | 255.255.255.192 |
| 126 | 7 | /25 | 255.255.255.128 |
| 254 | 8 | /24 | 255.255.255.0 |
| 510 | 9 | /23 | 255.255.254.0 |
| 1,022 | 10 | /22 | 255.255.252.0 |
| 2,046 | 11 | /21 | 255.255.248.0 |
| 4,094 | 12 | /20 | 255.255.240.0 |
| 8,190 | 13 | /19 | 255.255.224.0 |
| 16,382 | 14 | /18 | 255.255.192.0 |
| 32,766 | 15 | /17 | 255.255.128.0 |
| 65,534 | 16 | /16 | 255.255.0.0 |
The rule the tool uses: the longest prefix whose usable hosts are at least the number needed, so 26 hosts need a /27 (30 usable). 2 hosts get a /31 under RFC 3021; equipment that reserves a network and a broadcast address needs a /30 for them.
How to use this tool
- Choose All, Common or Classful, or leave All showing.
- Type a prefix, a mask, a wildcard or a host count in the search box. Commas and spaces are ignored, so 65536 and 65,536 both find /16.
- Press Copy on a row to copy its prefix, mask, wildcard, total and usable hosts as tab-separated text, or Copy table for every row shown, with a header line. Print gives a paper copy without the buttons.
Frequently asked questions
- What is the subnet mask for /24, /16 and /8?
- /24 is 255.255.255.0 with 254 usable hosts, /16 is 255.255.0.0 with 65,534, and /8 is 255.0.0.0 with 16,777,214. These are also the three classful sizes the Classful filter shows.
- How many usable hosts are in a /26 or a /27?
- A /26 has 64 addresses and 62 usable hosts; a /27 has 32 addresses and 30 usable hosts. Usable is the total minus the network and broadcast addresses.
- Why does a /31 have 2 usable hosts when the formula gives 0?
- RFC 3021 says that on a point-to-point link with a 31-bit mask the two addresses must be treated as host addresses, with no network or broadcast address. A /30 spends 4 addresses on two hosts, a /31 spends 2.
- What subnet mask do I need for 26 hosts?
- A /27, 255.255.255.224: it has 32 addresses and 30 usable hosts, while a /28 holds only 14. Pick the longest prefix whose usable count is at least what you need; the Hosts needed field does this for any number, and the table under it lists the break points from 2 hosts (/31) to 65,534 (/16).
- How many hosts does a /32 have?
- A /32 is a single address, and the tool shows 1 usable host. That is this tool’s convention: RFC 3021 does not mention /32.
- How do I find the prefix for a mask like 255.255.254.0?
- Type the mask in the search box. 255.255.254.0 is /23, with 512 addresses and 510 usable hosts. The wildcard 0.0.1.255 is the mask with every bit flipped.
Related Tools
View all toolsSubnet Mask Calculator
Subnet calculator for IPv4: enter an address and a mask or prefix such as /24 to get the network, broadcast address, host range, usable hosts and wildcard mask.
CIDR Calculator
Enter an IPv4 CIDR block such as 192.168.1.0/24 for its IP range, netmask, broadcast address and usable hosts, split it into subnets or turn a range into CIDR.
Shell Commands Cheat Sheet
Search or filter 83 common shell commands by level, topic and platform, and copy a name or example. 12 are tagged as Linux tools or not on a default Mac.
Git Command Builder
Pick a git action such as merge, reset, stash or push, fill in the fields and copy the command, quoted for the shell, with warnings for risky flags.
Regex Tester
Test a JavaScript regular expression on your own text: every match with its numbered and named groups and start and end positions, flag switches and replace.
Dockerfile Generator
Generate a Dockerfile from a form: pick a language, base image, ports, env vars, build and start commands, then copy or download the file.