How to use this calculator
Enter a dotted IPv4 address and a separate prefix length from 0 to 32. For example, enter 192.168.1.42 and 24. The address can be anywhere inside the subnet; the result identifies the network boundary.
The math behind it
Address count = 2^(32 − prefix) Network = floor(address / count) × count Last address = network + count − 1 Usable hosts = count − 2 for prefixes 0–30 /31: two point-to-point endpoints; /32: one host route
A worked example
192.168.1.42/24 belongs to 192.168.1.0/24 with mask 255.255.255.0, broadcast 192.168.1.255 and 254 conventional host addresses from .1 through .254.
Assumptions & precision
IPv4 only. Leading-zero octets are rejected to avoid ambiguous notation. /31 uses RFC 3021 point-to-point semantics; /32 represents one address. Neither has a subnet broadcast here. Counts describe mathematical address space, not actual reachability or assignability. Reserved blocks, cloud providers and gateways may reserve more addresses.
A common question
Why does /31 have two usable addresses?
On a point-to-point link, RFC 3021 allows both addresses as endpoints instead of reserving network and broadcast addresses. Do not assume this behavior on other link types.