Calculate the number of usable host addresses available in a subnet.
Every IPv4 subnet of prefix length p contains 2^(32−p) total addresses. Of these, the first is the network address and the last is the broadcast address, neither of which can be assigned to a host — so usable hosts = 2^(32−p) − 2. The exceptions are /31 (RFC 3021 point-to-point links, both addresses usable) and /32 (a single host route).
Total and usable hosts
total = 2^(32 − prefix); usable = total − 2
One address in every subnet is reserved as the network identifier and one as the broadcast address for that subnet, so they cannot be assigned to hosts.
A /24 has 2^(32−24) = 256 total addresses, minus 2 reserved addresses, giving 254 usable hosts.
A /32 has only one address and identifies a single host (a 'host route'). A /31, per RFC 3021, is defined so both of its two addresses can be used as endpoints of a point-to-point link, since there's no room for separate network/broadcast addresses.