What a Subnet Is and Why You Need to Calculate It
A subnet is a smaller network carved out of a larger one. When you divide an IP address range into subnets, you're deciding which devices can talk to each other directly without going through a router. To do this, you need to calculate three things: the subnet mask, the network address, and the broadcast address. These calculations tell you exactly which IP addresses belong to each subnet and which one is reserved for sending messages to all devices at once.
You calculate subnets because a single large network becomes slow and hard to manage. By breaking it into smaller pieces, you control traffic flow, improve security, and make troubleshooting faster. Whether you're setting up a small office network or planning a larger infrastructure, knowing how to do this math by hand—or understanding what the calculator is doing—keeps you from making mistakes that lock devices out of the network.
Key Takeaways
- A subnet mask written as /24 or 255.255.255.0 tells you how many bits of an IP address identify the network and how many identify individual devices.
- The network address is the first usable address in a subnet; the broadcast address is the last, and devices cannot be assigned to either one.
- To find usable host addresses, subtract 2 from the total number of addresses in the subnet (one for network, one for broadcast).
- CIDR notation like /25 is faster to work with than dotted-decimal notation, and both describe the same subnet mask.
- Subnetting works the same way whether you're using IPv4 or IPv6, but the math is simpler with online calculators once you understand the concept.
Understanding IP Addresses and Subnet Masks
An IPv4 address has four octets (groups of eight binary digits), written as four decimal numbers separated by dots—for example, 192.168.1.50. Each octet can hold a value from 0 to 255. A subnet mask is another four-octet number that sits on top of the IP address and marks which part belongs to the network and which part belongs to the host (the individual device).
The subnet mask uses 1s to mark network bits and 0s to mark host bits. A common subnet mask is 255.255.255.0, which in binary is 11111111.11111111.11111111.00000000. This mask says "the first three octets identify the network, and the last octet identifies the device." The same mask is written as /24 in CIDR notation, where the number means "24 bits are for the network." Learning to read both formats saves time when you see subnet information in different places.
The relationship between the subnet mask and the number of devices you can have is direct: if you have 8 host bits (a /24 network), you can create 2 to the power of 8, or 256 total addresses. But 2 of those are reserved—the network address (all host bits set to 0) and the broadcast address (all host bits set to 1)—so you have 254 usable addresses for actual devices.
How to Calculate the Network Address
The network address is the first address in a subnet. To find it, you perform a bitwise AND operation between the IP address and the subnet mask. In plain terms: line up the IP address and mask in binary, and write a 1 only where both have a 1; write 0 everywhere else.
Here is a worked example. Take the IP address 192.168.1.130 with a /24 subnet mask (255.255.255.0). Convert each octet to binary:
- 192 = 11000000
- 168 = 10101000
- 1 = 00000001
- 130 = 10000010
The subnet mask 255.255.255.0 in binary is 11111111.11111111.11111111.00000000. When you AND them together, the first three octets stay the same (because the mask is all 1s there), and the last octet becomes 0 (because the mask is all 0s there). The result is 192.168.1.0—that is your network address.
The network address is not assigned to any device; it identifies the subnet itself. In this example, all devices on the 192.168.1.0/24 network have IP addresses from 192.168.1.1 through 192.168.1.254.
How to Calculate the Broadcast Address
The broadcast address is the last address in a subnet. To find it, set all the host bits to 1. Using the same example (192.168.1.0/24), the host bits are the last octet. Setting all 8 bits to 1 gives you 11111111, which is 255 in decimal. So the broadcast address is 192.168.1.255.
When a device sends a message to the broadcast address, every device on that subnet receives it. Like the network address, the broadcast address is not assigned to any device—it is reserved for this special purpose. If you tried to give a computer the IP address 192.168.1.255 on a 192.168.1.0/24 network, it would conflict with the broadcast address and cause problems.
The range of usable addresses is always network address + 1 through broadcast address − 1. For 192.168.1.0/24, that is 192.168.1.1 to 192.168.1.254, giving you 254 addresses where you can actually put devices.
Working Through a Subnet Calculation Step by Step
Here is a complete worked example from start to finish. Suppose you have the IP address 10.20.30.40 and a /28 subnet mask. First, figure out how many host bits you have: 32 total bits in an IPv4 address minus 28 network bits equals 4 host bits.
With 4 host bits, you can have 2 to the power of 4, or 16 total addresses. Subtract 2 for the network and broadcast addresses, leaving 14 usable addresses for devices. The subnet mask for /28 is 255.255.255.240 (the last octet is 11110000 in binary, which is 240 in decimal).
Now find the network address. Convert 40 to binary: 00101000. AND it with 11110000 (the last octet of the mask): the result is 00100000, which is 32 in decimal. So the network address is 10.20.30.32. The broadcast address is 10.20.30.47 (set the last four bits to 1: 00101111 = 47). Usable addresses run from 10.20.30.33 to 10.20.30.46.
This same process works for any subnet mask. The only difference is the number of bits you are working with and how many addresses you end up with. Once you understand the pattern, you can explore it to any network.
Common Subnet Masks and What They Mean
| CIDR Notation | Dotted-Decimal Mask | Host Bits | Total Addresses | Usable Addresses |
|---|---|---|---|---|
| /24 | 255.255.255.0 | 8 | 256 | 254 |
| /25 | 255.255.255.128 | 7 | 128 | 126 |
| /26 | 255.255.255.192 | 6 | 64 | 62 |
| /27 | 255.255.255.224 | 5 | 32 | 30 |
| /28 | 255.255.255.240 | 4 | 16 | 14 |
| /30 | 255.255.255.252 | 2 | 4 | 2 |
| /32 | 255.255.255.255 | 0 | 1 | 1 |
The /24 mask is the most common in small office and home networks because it gives you 254 usable addresses without being wasteful. A /30 mask is often used for point-to-point links (like connections between routers) because it provides exactly 2 usable addresses. A /32 mask represents a single host and is used in routing tables to point to one specific device.
Larger networks use smaller CIDR numbers. A /16 mask (255.255.0.0) gives you 65,534 usable addresses, and a /8 mask (255.0.0.0) gives you over 16 million. The smaller the CIDR number, the larger the network.
Tools and When to Use Them Versus Hand Calculation
Once you understand the math, you can use a subnet calculator to speed up your work. Online calculators and command-line tools like ipcalc (on Linux) or built-in Windows utilities can compute network addresses, broadcast addresses, and usable ranges in seconds. Type in an IP address and subnet mask, and the tool shows you everything at once.
However, knowing how to do the calculation by hand is valuable for two reasons: it helps you spot mistakes when a tool gives you an unexpected answer, and it builds the mental model you need to design networks correctly in the first place. Many network engineers and system administrators still do quick subnet math in their heads for common masks like /24, /25, and /30.
For learning, start with hand calculation on paper. For production work where speed matters and mistakes are costly, use a tool you trust. The best approach is to do the math by hand first, then verify it with a calculator.
Frequently Asked Questions
What is the difference between CIDR notation and dotted-decimal notation?
CIDR notation (/24) is a shorthand that tells you how many bits are for the network. Dotted-decimal notation (255.255.255.0) shows the actual subnet mask as four octets. They describe the same thing—/24 and 255.255.255.0 are equivalent. CIDR is faster to write and read, but both formats appear in real-world network configurations.
Why can't I use the network address or broadcast address for a device?
The network address identifies the subnet itself, and the broadcast address is reserved for sending messages to all devices on that subnet at once. If you assigned either one to a device, it would conflict with these special purposes and break communication on the network.
How do I calculate subnets for IPv6?
IPv6 uses the same concept but with 128 bits instead of 32, and the math is simpler because IPv6 almost always uses /64 for local networks. The process is identical: AND the address with the mask to find the network address, and set all host bits to 1 to find the broadcast address. Most people use a calculator for IPv6 because the numbers are much larger.
What happens if I choose a subnet mask that is too small for my network?
If your subnet mask does not provide enough usable addresses for all your devices, some devices will not be able to connect. For example, a /28 mask gives only 14 usable addresses, so if you try to connect 20 devices, 6 of them will fail. Always calculate how many addresses you need and choose a mask that provides at least that many, plus room for growth.
Can I use a /31 or /32 subnet mask on a regular network?
A /32 mask is a single host and is used in routing tables, not for regular networks. A /31 mask gives 2 total addresses with 0 usable ones (both are reserved), but it is used in special cases like router-to-router links where the network and broadcast addresses are not needed. For normal device networks, stick with /24 or larger.