Computer Science · Network Engineering · IP Networking
IPv4 Subnet Calculator
Calculates IPv4 subnet mask, network address, broadcast address, host range, and total usable hosts from an IP address and CIDR prefix length.
Calculator
Formula
n is the CIDR prefix length (the number after the slash in CIDR notation, e.g. 24 in 192.168.1.0/24). The total number of addresses in the subnet is 2^(32−n). Subtracting 2 removes the network address (all host bits = 0) and the broadcast address (all host bits = 1), leaving the count of usable host addresses. The subnet mask is derived by setting the first n bits to 1 and the remaining (32−n) bits to 0.
Source: RFC 950 — Internet Standard Subnetting Procedure; RFC 4632 — Classless Inter-Domain Routing (CIDR).
How it works
IPv4 addressing uses 32-bit binary numbers, typically written in dotted-decimal notation (e.g., 192.168.1.0). CIDR (Classless Inter-Domain Routing), defined in RFC 4632, replaced the old classful A/B/C scheme and allows network engineers to allocate address space with fine-grained control. A CIDR prefix such as /24 means the first 24 bits of the address identify the network, and the remaining 8 bits identify individual hosts within that network. This flexibility is what makes modern internet routing and private network design efficient.
The subnet mask is derived by setting the first n bits (the prefix length) to 1 and all remaining (32 − n) bits to 0. For a /24, that yields 11111111.11111111.11111111.00000000 in binary, or 255.255.255.0 in dotted-decimal. The network address is found by performing a bitwise AND between the IP address and the subnet mask — this zeroes out all host bits. The broadcast address is found by OR-ing the network address with the wildcard mask (the bitwise complement of the subnet mask), which sets all host bits to 1. Usable host addresses are all addresses strictly between the network address and the broadcast address, giving 2^(32−n) − 2 hosts for any prefix shorter than /31. RFC 3021 permits /31 subnets for point-to-point links (2 usable addresses, no network or broadcast), and a /32 denotes a single host route.
Subnetting is applied in virtually every networking context: dividing a company's IP allocation into departmental VLANs, configuring AWS VPCs and Azure Virtual Networks, writing firewall ACL rules, implementing OSPF area boundaries, and aggregating routes with supernetting. Understanding how to derive all subnet parameters from an IP and prefix is essential for both the CCNA and CompTIA Network+ certification exams and for real-world network design work.
Worked example
Suppose a network engineer is assigned the block 10.20.30.0/22 and needs to know the full subnet details before configuring routers and firewalls.
Step 1 — Subnet Mask: A /22 prefix means 22 bits are set to 1. In binary: 11111111.11111111.11111100.00000000. Converting to dotted-decimal: 255.255.252.0.
Step 2 — Wildcard Mask: The complement of the subnet mask: 00000000.00000000.00000011.11111111 = 0.0.3.255.
Step 3 — Network Address: AND the IP 10.20.30.0 with the mask 255.255.252.0. The last two octets: 30 in binary is 00011110; AND with 11111100 gives 00011100 = 28. Result: 10.20.28.0.
Step 4 — Broadcast Address: OR the network address 10.20.28.0 with the wildcard 0.0.3.255. Third octet: 28 OR 3 = 31. Fourth octet: 0 OR 255 = 255. Result: 10.20.31.255.
Step 5 — Usable Host Range: First host = network address + 1 = 10.20.28.1. Last host = broadcast − 1 = 10.20.31.254.
Step 6 — Total and Usable Hosts: Total addresses = 2^(32−22) = 2^10 = 1,024. Usable hosts = 1,024 − 2 = 1,022.
This /22 block is large enough for a medium-sized office floor or a cloud subnet serving a significant number of virtual machines, with room for growth.
Limitations & notes
This calculator handles standard IPv4 unicast subnetting for CIDR prefixes /0 through /32. A /31 subnet is treated per RFC 3021 as a valid point-to-point link with 2 host addresses and no distinct network or broadcast address. A /32 is treated as a host route with a single address. The calculator does not handle IPv6 addressing, Variable Length Subnet Masking (VLSM) planning across multiple subnets, supernetting (route aggregation), or multicast address ranges (224.0.0.0/4). IP addresses must be valid dotted-decimal notation; the tool does not validate whether an address falls within private ranges (RFC 1918: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) or reserved ranges such as loopback (127.0.0.0/8) or link-local (169.254.0.0/16) — users should verify address class and purpose independently. For production network design, always cross-reference results with your organization's IP address management (IPAM) system.
Frequently asked questions
What is CIDR notation and how does the prefix length work?
CIDR (Classless Inter-Domain Routing) notation expresses an IP address and its subnet prefix as a single string, such as 192.168.1.0/24. The number after the slash is the prefix length — it tells you how many of the 32 bits in the address are used to identify the network. A /24 means 24 network bits and 8 host bits, yielding 256 total addresses (254 usable). Longer prefixes (larger numbers) create smaller subnets, and shorter prefixes create larger ones.
What is the difference between the network address and the broadcast address?
The network address is the first address in a subnet, where all host bits are zero. It identifies the subnet itself and cannot be assigned to a host. The broadcast address is the last address in a subnet, where all host bits are one. Packets sent to the broadcast address are delivered to every host on the subnet. Both addresses are reserved and reduce the count of assignable addresses by 2 in any standard subnet.
How do I calculate the number of usable hosts for a given prefix length?
The formula is 2^(32 − n) − 2, where n is the CIDR prefix length. The subtraction of 2 accounts for the reserved network and broadcast addresses. For example, a /26 gives 2^(32−26) − 2 = 2^6 − 2 = 64 − 2 = 62 usable hosts. The special cases /31 (2 usable, per RFC 3021 for point-to-point links) and /32 (1 host route) do not follow this formula.
What is a wildcard mask and where is it used?
A wildcard mask is the bitwise complement of the subnet mask — wherever the subnet mask has a 1, the wildcard has a 0, and vice versa. Wildcard masks are used primarily in Cisco router ACLs (Access Control Lists) and OSPF network statements to specify which bits of an address must match and which can vary freely. For a /24 subnet mask of 255.255.255.0, the wildcard mask is 0.0.0.255.
What is the difference between /31 and /30 subnets for point-to-point links?
A /30 subnet provides 4 total addresses, with 2 usable hosts and 2 wasted (network and broadcast) — traditionally used for point-to-point WAN links. RFC 3021 introduced /31 subnets specifically for point-to-point links, providing exactly 2 addresses with no network or broadcast reservation, eliminating waste. Modern routers and operating systems support /31, but some older equipment may not, so /30 is still common in legacy environments.
Last updated: 2025-01-15 · Formula verified against primary sources.