How it works
An IPv4 address is 32 bits. The CIDR prefix says how many leading bits are the network portion; the rest address hosts. Applying the mask with a bitwise AND gives the network address, and setting all host bits gives the broadcast address.
mask = 0xFFFFFFFF shifted left by (32 − prefix)
network = IP AND mask
broadcast = network OR (NOT mask)
usable hosts = 2^(32 − prefix) − 2
network = IP AND mask
broadcast = network OR (NOT mask)
usable hosts = 2^(32 − prefix) − 2
Common prefixes
| CIDR | Mask | Usable hosts |
|---|---|---|
| /24 | 255.255.255.0 | 254 |
| /25 | 255.255.255.128 | 126 |
| /26 | 255.255.255.192 | 62 |
| /30 | 255.255.255.252 | 2 |