What a subnet mask and CIDR prefix mean, explained with binary
How a /21 or 255.255.248.0 splits an IPv4 address into network and host bits, why two addresses are lost, and how to split a block into smaller subnets.
Open the Subnet calculator Free, in your browser, nothing uploaded.
Every device on a network has an IP address, and every address belongs to a block called a subnet. The prefix after the slash, as in /21, or a mask such as 255.255.248.0, says where that block starts and ends. This article explains the binary idea behind the subnet calculator so that the network, broadcast and host range stop being magic numbers. It is for students studying for networking exams, people setting up an office or home lab, and developers writing firewall rules. For the scheduled jobs that often run on those servers, see cron explainer; for addresses inside web links, URL encoder; and for encoded keys and certificates, base64 converter.
What it is
An IPv4 address is 32 bits, written as four numbers from 0 to 255 (each one byte, or 8 bits). A subnet divides those 32 bits into two parts:
- The network part: the first bits, shared by every address in the block.
- The host part: the remaining bits, which pick one device inside it.
The prefix length (the /21) is how many bits belong to the network. The subnet mask is the same thing written as an address: 21 ones followed by 11 zeros, which is 255.255.248.0. The wildcard mask is the mask flipped, 0.0.7.255, and is used in router access lists.
From those, everything else follows:
- Network address = address AND mask (host bits set to 0).
- Broadcast address = network address with all host bits set to 1.
- Total addresses = 2^(32 − prefix).
- Usable hosts = total − 2, because the network and broadcast addresses are not given to devices. Two exceptions: a /31 has two usable addresses for a point-to-point link (RFC 3021), and a /32 is one single host.
Splitting a block means taking a longer prefix. Each extra bit doubles the number of subnets and halves their size.
Some ranges are special. Private addresses (10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16, from RFC 1918) are for use inside homes and offices and are not routed on the internet.
How to use it
- Type an address with a prefix (
172.20.37.200/21) or with a mask after a space (172.20.37.200 255.255.248.0) in IP address and prefix. Or tap one of the samples. - Read the Result: network, broadcast, first and last host, host count, mask, wildcard and the kind of address.
- Look at In binary to see exactly where the network bits end.
- Under Split into smaller subnets, pick a New prefix, read the table and press Download CSV if you need it.
- Press Copy result to paste the details into a ticket or a document.
- For IPv6, type an address like
2001:db8:abcd::1/48to see its range and how many /64 networks it holds.
A worked example
A small company is given 172.20.37.200/21 for its office.
In binary, the address and mask are:
10101100.00010100.00100101.11001000 172.20.37.200
11111111.11111111.11111000.00000000 255.255.248.0
The first two bytes are fully inside the network part, so they stay 172.20. The third byte, 37, is 00100101. Only its first 5 bits are network bits (8 + 8 + 5 = 21), so the host bits 101 are cleared: 00100000 = 32. The last byte is all host bits and becomes 0.
- Network: 172.20.32.0
- Broadcast: 172.20.39.255 (third byte 00100111 = 39, last byte 255)
- Total addresses: 2^(32 − 21) = 2^11 = 2,048
- Usable hosts: 2,046, from 172.20.32.1 to 172.20.39.254
- Wildcard: 0.0.7.255
- Kind: private, inside 172.16.0.0/12
Typing 172.20.37.200 255.255.248.0 gives the same /21.
The company wants one subnet per floor and a few for servers and guests, so it splits the /21 into /24 blocks. That is 3 extra bits, so 2³ = 8 subnets of 256 addresses each: 172.20.32.0/24, 172.20.33.0/24 and so on up to 172.20.39.0/24, each with 254 usable hosts.
Checked with the tools
All of these numbers came from the calculator’s own code (src/lib/dev/ip.ts) run in Node. parseCidr() returned the network, broadcast, first and last host, 2,046 hosts and the wildcard for both the prefix and the mask form; bin() gave the two binary lines; kind() called it private (RFC 1918); and split() at /24 returned 8 rows from 172.20.32.0 to 172.20.39.0, each with 254 hosts. A /31 test returned 2 usable hosts, as RFC 3021 says.
Where it is used
- Office and home networks. Choosing a router’s LAN range and DHCP pool so it does not clash with a VPN or a second site.
- Cloud networks. Planning virtual network blocks and the smaller subnets inside them, which cannot overlap.
- Firewalls and access lists. Allowing a whole range with one rule, written as a prefix or a wildcard mask.
- Exams and training. Subnetting by hand is a classic networking exam skill; the binary view checks each step.
Common mistakes
- Forgetting the two lost addresses. A /24 has 256 addresses but 254 hosts. Plan for the smaller number.
- Using the typed address as the network. 172.20.37.200/21 is a host inside 172.20.32.0/21, not a network of its own.
- Overlapping blocks. Two sites both using 192.168.1.0/24 cannot be joined cleanly by a VPN. Pick unusual private ranges early.
- Counting from the wrong byte. In a /21 the boundary falls inside the third byte, so the third number changes in steps of 8 (32, 40, 48 …), not 1.
Questions people ask
Why do people say “a /24” instead of the mask? It is shorter and works the same way for every size. 255.255.255.0 and /24 mean the same thing.
Can a mask have zeros in the middle, like 255.0.255.0? Not in modern networking: the ones must be continuous from the left, which is what a prefix length describes.
How is IPv6 different? Addresses are 128 bits written in hexadecimal, there is no broadcast address, and a single LAN is normally a /64.
Sources
- CIDR notation from RFC 4632; private ranges from RFC 1918; /31 point-to-point links from RFC 3021; IPv6 addressing from RFC 4291 and documentation range from RFC 3849. fibub's own working.
If you are an author or publisher and want a credit or a passage changed or removed, tell us and we will act quickly.