How this is calculated
The prefix length is the number of leading bits belonging to the network. A /24 means the first 24 bits are network and the remaining 8 are host, which gives a mask of 255.255.255.0 — 24 ones followed by 8 zeros.
The network address is the IP with all host bits set to zero; the broadcast address is the same with all host bits set to one. Usable hosts are everything in between, which is 2^(32 − prefix) − 2.
Worked example on 192.168.1.10/24: the mask is 255.255.255.0, the network address is 192.168.1.0, the broadcast is 192.168.1.255, and the usable range is 192.168.1.1 to 192.168.1.254 — 254 hosts from 256 addresses.
Why two addresses are always unusable
The all-zeros host address identifies the network itself and is what appears in routing tables. The all-ones host address is the broadcast address, which reaches every host on the segment at once. Neither can be assigned to an interface, which is where the minus two comes from.
The cost of this is proportionally brutal on small subnets. A /30 has 4 addresses and 2 usable hosts — half the space lost to overhead. A /24 loses 2 out of 256, which is negligible. This is why point-to-point links, which need exactly two addresses, were so wasteful before /31 support existed.
RFC 3021 permits /31 on point-to-point links precisely to fix that, giving 2 usable addresses from 2 by dispensing with network and broadcast addresses entirely. A /32 describes a single host and is used for loopbacks and host routes.
Reading a mask without a table
Each octet of a mask can only take nine values: 0, 128, 192, 224, 240, 248, 252, 254, 255 — corresponding to 0 through 8 bits set. A mask octet of 192 means two bits, so a /18 is 255.255.192.0.
The block size in the last significant octet is 256 minus that octet's value. A /26 has a mask of 255.255.255.192, so the block size is 64 and the subnets start at .0, .64, .128 and .192. This is the fastest way to work out which subnet an address falls in without converting anything to binary.
The wildcard mask, which appears in access control lists and OSPF configuration, is the mask inverted — 0.0.0.255 for a /24. It is the same information expressed the other way round, matching bits that are allowed to vary rather than bits that must match.
How to use the ip subnet calculator
- Enter an address with its prefix. Standard CIDR notation, such as 10.0.5.37/22. Any address within the subnet works — you do not need the network address.
- Read the network and broadcast addresses. These bound the subnet. Neither can be assigned to a host.
- Use the host range for assignment. Everything between the two bounds is assignable. The count is 2^(32 − prefix) − 2, except on /31 and /32.