Subnet Mask Calculator
Usable hosts, total addresses and the four octets of the subnet mask for a CIDR prefix.
Results
What this tool does
The prefix is how many bits from the left are fixed by the network, so a bigger number means a smaller subnet — which catches people out constantly. A /24 is the familiar 255.255.255.0 with 254 hosts; a /26 quarters it. The last result counts how many subnets of that size fit inside one /24.
Formula
machines = 2^(32 − prefix) − 2
Variables
| Symbol | Meaning | Unit |
|---|---|---|
pf | Prefix length (CIDR) | — |
HS | Usable hosts | — |
AD | Total addresses | — |
M1 | Mask octet | — |
M2 | Mask octet | — |
M3 | Mask octet | — |
M4 | Mask octet | — |
SN | Subnets in a /24 | — |
Worked example
- Prefix length (CIDR)26
- Usable hosts62
- Total addresses64
- Mask octet255
- Mask octet255
- Mask octet255
- Mask octet192
- Subnets in a /244
Limitations
- For work that must comply with a standard or be signed off, check the result against the applicable code and have it reviewed by a qualified engineer.
- The calculation runs at full precision and only the display is rounded. If you copy an intermediate value and retype it, small differences can appear.
Frequently asked questions
Why subtract two from the host count?
Because two addresses in every ordinary subnet are reserved: the first, with all host bits zero, names the network itself, and the last, with all host bits one, is the broadcast address. Neither can be given to a machine. That is why a /30 — four addresses — gives only two usable ones, which is exactly enough for the two ends of a point-to-point link, and why /31 exists as a special case for that job without the waste.