Subnet Mask / CIDR Calculator

Enter an IPv4 address and a CIDR prefix length (0–32) to calculate the subnet mask, network address, broadcast address, usable host range, and total number of usable hosts.

Results will appear here.

Formulas

Subnet Mask — A 32-bit mask with the first n bits set to 1 (network portion) and the remaining 32 − n bits set to 0 (host portion):

mask = (0xFFFFFFFF << (32 − n)) & 0xFFFFFFFF

Network Address — Bitwise AND of the IP address and the subnet mask:

network = IP & mask

Broadcast Address — Network address OR the bitwise complement (wildcard) of the mask:

broadcast = network | (~mask & 0xFFFFFFFF)

Wildcard Mask — Bitwise complement of the subnet mask:

wildcard = ~mask & 0xFFFFFFFF

Usable Hosts — Total addresses minus network and broadcast addresses (for /0–/30):

hosts = 2(32 − n) − 2

Special cases: /31 = 2 hosts (RFC 3021 point-to-point links); /32 = 1 host route.

Assumptions & References

  • IPv4 addresses only (32-bit); IPv6 is not supported.
  • CIDR notation follows RFC 4632 (Classless Inter-Domain Routing).
  • /31 subnets are treated per RFC 3021 — both addresses are usable on point-to-point links.
  • /32 is a host route; the single address is both network and broadcast.
  • Private address ranges follow RFC 1918: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16.
  • IP class (A/B/C/D/E) is shown for informational purposes only; classful routing is obsolete.
  • All bit operations use JavaScript's 32-bit unsigned right-shift (>>> 0) to ensure correct unsigned arithmetic.

In the network