IPv4 Subnet Calculator
Enter an IP address and a CIDR prefix length (e.g., 192.168.1.0/24) to see every detail about that subnet — including the formulas used to compute each value.
Reviewed by the ToolNestr Editorial Team — July 2026
Enter IP and CIDR prefix
How subnet calculation works
Every IPv4 address is 32 bits long. A subnet mask defines how many of those bits belong to the network portion and how many belong to the host portion. The CIDR notation — a forward slash followed by a number — tells you the prefix length, which is the number of leading bits that are fixed for the network. For example, 192.168.1.0/24 means the first 24 bits identify the network and the remaining 8 bits are available for hosts.
The subnet calculator performs three fundamental operations. First, it computes the subnet mask by setting the first N bits to 1 and the remaining bits to 0. For a /24, the mask in binary is 24 ones followed by 8 zeros, which in decimal is 255.255.255.0. Second, it computes the network address by performing a bitwise AND between the IP address and the subnet mask. This zeros out all host bits, leaving only the network portion. Third, it computes the broadcast address by taking the network address and setting all host bits to 1.
The usable host range starts at network address plus 1 and ends at broadcast address minus 1. The total number of usable hosts is 2^(32 - prefix) - 2, because the network and broadcast addresses are reserved. For a /24, that is 2^8 - 2 = 254 usable addresses. The wildcard mask is the bitwise inverse of the subnet mask and is used in ACLs (access control lists) and routing protocols like OSPF.
The formulas behind the calculator
Subnet Mask
Set the first N bits to 1, remaining to 0. mask = (2^N - 1) << (32 - N)
Network Address
Bitwise AND of IP and mask. network = ip AND mask
Broadcast Address
Bitwise OR of IP and inverted mask. broadcast = ip OR NOT(mask)
Usable Hosts
Total addresses minus 2. hosts = 2^(32 - prefix) - 2
Why subnetting matters
Subnetting is one of the most fundamental concepts in network design. Without subnetting, every device on a network would compete for bandwidth and receive every broadcast packet, leading to congestion and security vulnerabilities. By dividing a large network into smaller subnets, administrators can isolate traffic, contain broadcast domains, apply access control policies, and allocate addresses more efficiently.
In enterprise environments, subnetting enables network segmentation for security purposes. A finance department might be on a separate subnet from engineering, with firewall rules controlling traffic between them. This limits the blast radius of a security breach and simplifies compliance with data protection regulations such as PCI DSS and HIPAA.
Variable Length Subnet Masking (VLSM), defined in RFC 1009, allows subnets of different sizes within the same network. This avoids wasting IP addresses by matching subnet sizes to actual host counts. For example, a point-to-point link between two routers only needs a /30 subnet (2 usable addresses), while a busy office might need a /23 (510 usable addresses). VLSM is a core feature of modern routing protocols including OSPF, EIGRP, and ISIS.
Subnet calculation is also essential for troubleshooting connectivity issues. If two devices cannot communicate despite being on the same physical network, the most common cause is incorrect subnet mask configuration. One device may believe the other is on a different subnet and try to route traffic through a default gateway that does not exist or is misconfigured. The ping and traceroute commands together with subnet knowledge form the foundation of network diagnostics.
Common subnet sizes reference
| CIDR | Subnet Mask | Total Addresses | Usable Hosts |
|---|---|---|---|
| /30 | 255.255.255.252 | 4 | 2 |
| /29 | 255.255.255.248 | 8 | 6 |
| /28 | 255.255.255.240 | 16 | 14 |
| /27 | 255.255.255.224 | 32 | 30 |
| /26 | 255.255.255.192 | 64 | 62 |
| /25 | 255.255.255.128 | 128 | 126 |
| /24 | 255.255.255.0 | 256 | 254 |
| /23 | 255.255.254.0 | 512 | 510 |
| /22 | 255.255.252.0 | 1024 | 1022 |
| /21 | 255.255.248.0 | 2048 | 2046 |
| /20 | 255.255.240.0 | 4096 | 4094 |
Classful addressing vs. CIDR
Before CIDR was standardized in 1993 (RFC 1519, later updated by RFC 4632), IP addresses were allocated using classful addressing. Class A networks used a /8 prefix with 16 million addresses, Class B used /16 with 65,536 addresses, and Class C used /24 with 256 addresses. This rigid structure wasted enormous numbers of IP addresses — a company needing 300 addresses had to be allocated a Class B /16, wasting 65,236 addresses.
CIDR (Classless Inter-Domain Routing) eliminated these fixed boundaries and allowed any prefix length from /0 to /32. This enabled much finer-grained address allocation and dramatically slowed the depletion of the IPv4 address pool. CIDR also introduced route aggregation (supernetting), where a single routing table entry could represent many contiguous smaller networks, reducing the size of global routing tables. Today, all internet routing is based on CIDR principles, and classful addressing is considered obsolete.
Limitations and considerations
This calculator works with standard IPv4 CIDR notation. It does not handle IPv6 subnets (which use a different address format and /64 as the typical subnet boundary). The calculation assumes a flat subnet without considering secondary IPs, VLAN interfaces, or overlapping address spaces common in complex network topologies. For networks using NAT, PAT, or carrier-grade NAT, the usable address count at the WAN interface differs from what the subnet math suggests.
Subnet calculators help with design and verification but cannot replace a proper IP address management (IPAM) system for large-scale deployments. In production networks with thousands of subnets, manual calculation is error-prone and IPAM tools should be used to track allocations, detect overlaps, and manage DHCP scopes. The calculator is best used for quick ad-hoc checks, studying for networking certifications (CompTIA Network+, CCNA), and learning the underlying binary arithmetic.
Frequently asked questions
What is a subnet?
A subnet is a logical subdivision of an IP network. Subnetting divides a large network into smaller, manageable pieces to improve performance, security, and address utilization. Each subnet has its own network address, broadcast address, and range of usable host addresses.
What is a subnet mask?
A subnet mask is a 32-bit number that separates the network portion of an IP address from the host portion. Bits set to 1 represent the network part, bits set to 0 represent the host part. For example, 255.255.255.0 (or /24) means 24 bits for the network and 8 bits for hosts.
What is the network address?
The network address is the first address in a subnet range. It identifies the subnet itself and cannot be assigned to a host. It is calculated by performing a bitwise AND between the IP address and the subnet mask.
What is the broadcast address?
The broadcast address is the last address in a subnet range. Packets sent to this address are received by all hosts on the subnet. It cannot be assigned to a host. It is calculated by performing a bitwise OR between the IP address and the inverted subnet mask.
How many usable hosts are in a /24 subnet?
A /24 subnet has 256 total addresses. Subtracting the network address (first) and broadcast address (last) leaves 254 usable host addresses. The formula is 2^(32 - prefix) - 2.
What does CIDR stand for?
CIDR stands for Classless Inter-Domain Routing, defined in RFC 4632. It replaced the older classful addressing system (Class A, B, C) and allows prefix lengths of any value from 0 to 32, enabling more flexible and efficient IP address allocation.
What is the difference between /24 and /25?
A /24 subnet contains 256 total addresses with 254 usable hosts. A /25 subnet contains 128 total addresses with 126 usable hosts. Each bit change in the prefix length halves or doubles the subnet size.
Why are the first and last addresses reserved?
The first address (all host bits zero) identifies the network itself. The last address (all host bits one) is used for broadcasting to all hosts on the subnet. Both are reserved by the IP protocol specification (RFC 1122) and cannot be assigned to interfaces.