HOW IT WORKS
IPv4 bitwise CIDR & subnetting math
IPv4 addresses are 32-bit unsigned integers. Applying a contiguous subnet mask via bitwise AND isolates the network prefix, while bitwise OR with the wildcard mask yields the broadcast address.
Derive Mask & Wildcard
A CIDR prefix /p sets the top p bits to 1 and the remaining 32 − p host bits to 0. The wildcard mask is the bitwise inverse.
Wildcard = ~Mask (unsigned 32-bit)Compute Network & Broadcast
Bitwise AND of the IP and mask clears all host bits to find the network address; setting host bits to 1 produces the broadcast address.
Network = IP & Mask · Broadcast = Network | WildcardCount Usable Hosts
Standard subnets reserve network and broadcast addresses (2^(32−p) − 2). Point-to-point /31 links (RFC 3021) allow 2 usable hosts, and /32 represents 1 host route.
Usable = Total − 2 (for /0–/30)