The formula
hosts = 2^(32 − prefix) − 2
Where it comes from
The prefix says how many bits identify the network; the rest identify each host. A /24 leaves 8 bits free, which is 256 addresses, less two: the first identifies the network and the last is the broadcast address.
How to work it out by hand
- Subtract the prefix from 32 to see how many bits are left for hosts
- Raise 2 to that number: those are the total addresses
- Subtract 2 for the network and broadcast addresses
- The mask is as many ones as the prefix says, followed by zeros
What is worth knowing
Private addresses are the ones that are not routed over the internet and can be used freely on a local network: 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. The /31 and /32 prefixes are special cases: on point-to-point links no network or broadcast address is reserved, so every address is used.