You are setting up a cloud VPC and the console asks for a CIDR block. A firewall rule needs "the whole office range". A colleague says the new VLAN is a /26 and you are not sure how many devices that leaves room for. Subnetting questions come up constantly, and getting them wrong means overlapping ranges, unreachable hosts or firewall rules that are wider than intended.
This guide explains what a subnet mask and CIDR prefix really are, how to calculate the network, broadcast and host range yourself, and how to divide a block into equal smaller subnets. It covers IPv4, which is where masks and host counts cause the most day-to-day confusion.
An IPv4 address is a 32-bit number
192.168.1.10 is just a friendly way of writing 32 bits, split into four 8-bit octets:
192 .168 .1 .10
11000000.10101000.00000001.00001010
A subnet divides those 32 bits into two parts. The left part, the network portion, is the same for every device on the subnet. The right part, the host portion, identifies individual devices.
Subnet masks and CIDR prefixes
A subnet mask marks the network portion with ones and the host portion with zeros. 255.255.255.0 is 24 ones followed by 8 zeros:
11111111.11111111.11111111.00000000
CIDR notation writes the same thing as a count of the ones: /24. So 192.168.1.10/24 and "192.168.1.10 with mask 255.255.255.0" mean the same. CIDR (Classless Inter-Domain Routing) replaced the old fixed Class A, B and C networks in the 1990s, which is why any prefix from /0 to /32 is valid today.
The wildcard mask is the inverse (0.0.0.255 for a /24). Cisco ACLs and some OSPF configurations use it.
Calculating a subnet by hand
Everything follows from two bitwise operations:
- Network address = IP AND mask (keep the network bits, zero the host bits).
- Broadcast address = network OR inverted mask (set all host bits to one).
- Usable hosts = every address in between.
- Total addresses = 2^(32 − prefix). Usable hosts = total − 2.
A worked example with a less friendly prefix, 172.16.37.200/20:
- A /20 mask is 20 ones:
255.255.240.0. Only the third octet is "interesting" (240 =11110000). - The block size in the third octet is 256 − 240 = 16. Multiples of 16 are 0, 16, 32, 48 and so on.
- 37 falls between 32 and 48, so the network is
172.16.32.0. - The broadcast is one below the next block:
172.16.47.255. - Usable hosts run from
172.16.32.1to172.16.47.254: 2^12 − 2 = 4,094 addresses.
The "block size" shortcut (256 minus the interesting mask octet) is the fastest mental method. For scripts, the bitwise version is just as short in JavaScript:
const toInt = (ip) => ip.split(".").reduce((n, o) => (n << 8) + Number(o), 0) >>> 0;
const toIp = (n) => [24, 16, 8, 0].map((s) => (n >>> s) & 255).join(".");
function subnet(cidr) {
const [ip, bits] = cidr.split("/");
const prefix = Number(bits);
const mask = prefix === 0 ? 0 : (0xffffffff << (32 - prefix)) >>> 0;
const network = (toInt(ip) & mask) >>> 0;
const broadcast = (network | ~mask) >>> 0;
return { mask: toIp(mask), network: toIp(network), broadcast: toIp(broadcast) };
}
console.log(subnet("172.16.37.200/20"));
// { mask: '255.255.240.0', network: '172.16.32.0', broadcast: '172.16.47.255' }
The >>> 0 keeps the results as unsigned 32-bit numbers; without it JavaScript's bitwise operators return negative values for addresses above 128.0.0.0.
Quick reference for common prefixes
| Prefix | 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 |
| /24 | 255.255.255.0 | 256 | 254 |
| /20 | 255.255.240.0 | 4,096 | 4,094 |
| /16 | 255.255.0.0 | 65,536 | 65,534 |
Two special cases: a /31 has two addresses and no broadcast, and RFC 3021 allows both to be used on point-to-point links. A /32 is a single host, often used for loopbacks and firewall rules.
Cloud providers usually reserve more than two addresses per subnet for their own routers and DNS, so check your provider's documentation for the real usable count.
Check your work with the calculator
The IP Subnet Calculator does all of this at once and shows the bits.
- Type an address into IP address or CIDR, for example
172.16.37.200/20. You can also write the mask after the slash (10.1.2.3/255.255.0.0). - If you type an address without a slash, pick the prefix from the Subnet mask list instead, which shows each prefix with its dotted mask.
- Read the results table: Subnet mask, Wildcard mask, Network address, Broadcast address, First usable host, Last usable host, Usable hosts and Total addresses, plus the IP class, Address type (private, loopback, CGNAT and so on) and Reverse DNS zone.
- Look at the Binary view to see exactly where the mask cuts the address.
- To divide the range, choose a size under Split this network into. The table lists each subnet with its usable range and broadcast. Click Copy list to take the CIDR blocks.
The split list shows up to 256 subnets at a time and tells you how many exist in total.
Splitting a network into subnets
Each extra prefix bit halves the block. A /24 gives two /25s, four /26s, eight /27s and so on. When planning:
- Size for growth. A team of 25 fits a /27 (30 hosts) today, but a /26 leaves room without renumbering later.
- Keep blocks aligned. A /26 must start at .0, .64, .128 or .192. You cannot start one at .50.
- Different sizes can share a parent. Variable-length subnetting (VLSM) lets you carve one /25 and two /26s from the same /24. Allocate the largest blocks first to avoid fragmentation.
Pitfalls to watch for
Overlapping ranges
Two subnets overlap if one's network address falls inside the other. VPN and VPC peering fail silently or refuse to connect when ranges overlap, so pick distinct private ranges for each site early.
Private versus public space
The private ranges from RFC 1918 are 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. Note that 172.16.0.0/12 runs up to 172.31.255.255, not all of 172.x. 100.64.0.0/10 is shared carrier-grade NAT space and should not be used as if it were yours.
Typing the host address as the network
Routes and firewall rules usually expect the network address. Many systems will reject or silently correct 192.168.1.10/24 in a route; write 192.168.1.0/24.
If you work with number bases a lot, the number base converter is handy for checking a single octet in binary or hex, and text to binary shows the same bit patterns for arbitrary strings. Once the network is planned, server-side work such as setting file modes on config files is covered by the chmod calculator.
Frequently asked questions
How many usable hosts are in a /24?
A /24 has 256 addresses. Subtracting the network and broadcast addresses leaves 254 usable hosts.
What is the difference between a subnet mask and CIDR?
They express the same information. A mask writes the network bits as a dotted number (255.255.255.0), while CIDR writes how many bits are set (/24).
Why can't I use the first and last address?
In a normal subnet the first address identifies the network itself and the last is the broadcast address. Only /31 point-to-point links and /32 single hosts are exceptions.
Is 172.20.0.0 a private address?
Yes. The private block 172.16.0.0/12 covers 172.16.0.0 to 172.31.255.255, so 172.20.x.x is inside it.
Does this work for IPv6?
The idea of a prefix is the same, but IPv6 has 128-bit addresses, no broadcast, and LANs are normally /64. This calculator handles IPv4 only.