Separate the network bits from the host bits
An IPv4 address has 32 bits. The prefix says how many belong to the network. For /24:
| Step | Working |
|---|---|
| Host bits | 32 − 24 = 8 |
| Total addresses | 28 = 256 |
| Conventional usable hosts | 256 − 2 = 254 |
The subnet mask has ones for network bits and zeros for host bits. The wildcard mask reverses those bits. The /31 and /32 exceptions are explained below.
For 192.168.1.20/24, the network is 192.168.1.0, the mask is 255.255.255.0, and the broadcast is 192.168.1.255. The conventional host range runs from 192.168.1.1 to 192.168.1.254, giving 254 hosts. RFC 4632 describes CIDR addressing.
How /31 and /32 differ
A /31 has two addresses and can use both on a point-to-point link under RFC 3021. A /32 identifies one address. Neither receives a separate broadcast address in this result.
Larger blocks can contain reserved or otherwise unsuitable addresses. The arithmetic does not check allocation registries, routing policies, or your organization’s network plan.