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.
IPv6 prefixes
A /p IPv6 prefix contains 2^(128 − p) addresses. The network clears the last 128 − p bits and the last address sets them. IPv6 has no broadcast address, so all addresses are counted. Addresses are shown expanded and in the RFC 5952 compressed form, and the prefix list shows the networks containing the address at common lengths from /16 to /128.
Worked example: IPv6
2001:db8:85a3::8a2e:370:7334/64 belongs to 2001:db8:85a3::/64. The prefix runs from 2001:0db8:85a3:0000:0000:0000:0000:0000 to 2001:0db8:85a3:0000:ffff:ffff:ffff:ffff and holds 2^64 = 18,446,744,073,709,551,616 addresses.