Formula and method
A /p block has 2^(32 − p) addresses. Clear host bits for the network boundary. Ordinary subnets reserve network and broadcast addresses; /31 point-to-point links and /32 hosts are handled separately.
Worked example
192.168.1.42/24 belongs to 192.168.1.0/24. Its mask is 255.255.255.0 and ordinary usable addresses run from .1 through .254.