How to Calculate an IP Address From a Subnet Mask
Understanding how IP addresses and subnet masks work together is one of those networking fundamentals that unlocks a lot of clarity about how devices communicate on a network. Whether you're configuring a router, troubleshooting a connection, or studying for a certification, knowing how to extract meaningful information from a subnet mask is an essential skill.
What a Subnet Mask Actually Does
An IP address (IPv4) is a 32-bit number written in four groups of decimal digits — like 192.168.1.45. On its own, that address doesn't tell you which part identifies the network and which part identifies the host (the specific device).
That's where the subnet mask comes in. It's also a 32-bit number — like 255.255.255.0 — and it acts as a filter that separates those two portions.
When you convert both the IP address and the subnet mask to binary, the subnet mask's 1 bits mark the network portion, and the 0 bits mark the host portion.
| Decimal | Binary |
|---|---|
| 192.168.1.45 | 11000000.10101000.00000001.00101101 |
| 255.255.255.0 | 11111111.11111111.11111111.00000000 |
In this example, the first 24 bits are the network portion and the last 8 bits are the host portion.
The Core Calculation: Network Address
To find the network address — the base address that identifies the subnet — you perform a bitwise AND operation between the IP address and the subnet mask.
Bitwise AND means: compare each bit position. If both bits are 1, the result is 1. Otherwise, it's 0.
Example:
- IP: 192.168.1.45 → 11000000.10101000.00000001.00101101
- Mask: 255.255.255.0 → 11111111.11111111.11111111.00000000
- AND result: 11000000.10101000.00000001.00000000 → 192.168.1.0
So the network address is 192.168.1.0. Every device on this subnet shares that base.
Calculating the Broadcast Address
The broadcast address is the highest address in the subnet — the one used to send a message to every device on the network simultaneously.
To find it, take the network address and flip all the host bits to 1.
Using the same example:
- Network: 11000000.10101000.00000001.00000000
- Flip host bits: 11000000.10101000.00000001.11111111
- Broadcast: 192.168.1.255
Finding the Usable Host Range
The usable IP addresses for devices sit between the network address and the broadcast address — exclusive of both.
- First usable host: Network address + 1 → 192.168.1.1
- Last usable host: Broadcast address − 1 → 192.168.1.254
- Total usable hosts: 254 (for a /24 subnet, that's 2⁸ − 2)
The formula for total usable hosts is: 2ⁿ − 2, where n is the number of host bits.
CIDR Notation and Prefix Length 🌐
You'll often see subnet masks written in CIDR notation — a slash followed by a number, like /24. That number is simply the count of 1 bits in the subnet mask.
| CIDR | Subnet Mask | Host Bits | Usable Hosts |
|---|---|---|---|
| /8 | 255.0.0.0 | 24 | 16,777,214 |
| /16 | 255.255.0.0 | 16 | 65,534 |
| /24 | 255.255.255.0 | 8 | 254 |
| /28 | 255.255.255.240 | 4 | 14 |
| /30 | 255.255.255.252 | 2 | 2 |
Converting between the two is straightforward: count the consecutive 1 bits in the mask to get the prefix length, or expand the prefix length into binary to get the mask.
Variable-Length Subnet Masks (VLSM)
Not all subnet masks are clean boundaries at octet edges. A mask like 255.255.255.192 — or /26 — splits the last octet, which trips up many people doing this by hand.
Example with /26:
- IP: 10.0.0.130
- Mask: 255.255.255.192 → 11111111.11111111.11111111.11000000
- AND result: 10.0.0.128 (network address)
- Host bits: 6 → 2⁶ − 2 = 62 usable hosts
- Broadcast: 10.0.0.191
- Usable range: 10.0.0.129 to 10.0.0.190
The tricky part here is that converting 192 to binary (11000000) shows only 2 bits are borrowed for the network portion within that final octet — leaving 6 for hosts.
Tools That Do This Automatically 🔢
For everyday use, subnet calculators handle all of this instantly. You input an IP and mask (or CIDR notation), and they return the network address, broadcast address, host range, and usable host count. Common tools include:
- Command-line utilities like ipcalc on Linux
- Online subnet calculators
- Built-in calculators in network management platforms
Doing it manually is still worth understanding — it reveals what those tools are actually computing.
The Variables That Affect Your Setup
The "right" subnet size and configuration depend on factors specific to each network environment:
- Number of devices that need addresses on the segment
- Network segmentation goals — security zones, VLANs, department isolation
- IP address space available — private ranges like 10.x.x.x, 172.16–31.x.x, or 192.168.x.x have different scale limits
- Router and switch capabilities — some consumer hardware handles fewer subnets cleanly
- Growth expectations — subnetting too tightly leaves no room for additional hosts
A home network with five devices and a small business with 200 workstations across multiple departments will arrive at very different subnetting decisions, even using the same calculation methods.
How you apply these calculations depends entirely on the size, structure, and goals of the network you're working with — and that's the piece no general guide can answer for you.