How to Calculate an IPv4 Subnet Range From Any IP Address
A CIDR value such as:
192.168.1.130/26
contains two pieces of information:
-
192.168.1.130is an address inside the subnet -
/26means the first 26 bits identify the network
The entered address does not need to be the network address. You can calculate the containing network from any valid address inside the range.
In this example, the result is:
Network: 192.168.1.128/26
Broadcast: 192.168.1.191
First usable: 192.168.1.129
Last usable: 192.168.1.190
Subnet mask: 255.255.255.192
Wildcard mask: 0.0.0.63
Total addresses: 64
Usable hosts: 62
Here is how to calculate every value manually.
Step 1: Convert the prefix into host bits
IPv4 addresses contain 32 bits.
A /26 prefix reserves 26 bits for the network:
Host bits = 32 - 26
Host bits = 6
The subnet therefore contains:
2⁶ = 64 addresses
For a normal subnet, the lowest address identifies the network and the highest address is the broadcast address.
That leaves:
64 - 2 = 62 usable host addresses
Step 2: Find the subnet mask
A /26 mask contains 26 ones followed by 6 zeros:
11111111.11111111.11111111.11000000
Convert each octet to decimal:
255.255.255.192
So the subnet mask is:
255.255.255.192
Step 3: Calculate the block size
The interesting octet is the first mask octet that is not 255.
For /26, that octet is 192.
Calculate the block size:
Block size = 256 - 192
Block size = 64
The possible subnet boundaries in the final octet are therefore:
0
64
128
192
Each range contains 64 addresses:
0–63
64–127
128–191
192–255
The entered address ends in 130.
Since 130 falls between 128 and 191, its network is:
192.168.1.128/26
Step 4: Find the broadcast address
The broadcast address is the final address in the subnet.
The selected block runs from:
192.168.1.128
through:
192.168.1.191
Therefore:
Broadcast address = 192.168.1.191
Another way to calculate it is:
Broadcast = Network + Total addresses - 1
Broadcast = 128 + 64 - 1
Broadcast = 191
Step 5: Find the usable host range
For a traditional IPv4 subnet:
First usable = Network + 1
Last usable = Broadcast - 1
That gives:
First usable: 192.168.1.129
Last usable: 192.168.1.190
The same calculation in binary
The final octet of the entered IP is 130:
130 = 10000010
The final octet of the /26 mask is 192:
192 = 11000000
Apply the mask to the address:
IP: 10000010
Mask: 11000000
Network: 10000000
10000000 is 128, giving:
192.168.1.128
Set all six host bits to 1 to find the broadcast address:
Network: 10000000
Broadcast: 10111111
10111111 is 191, giving:
192.168.1.191
Quick CIDR reference
| Prefix | Subnet mask | Total addresses | Traditional usable hosts |
|---|---|---|---|
/24 |
255.255.255.0 |
256 | 254 |
/25 |
255.255.255.128 |
128 | 126 |
/26 |
255.255.255.192 |
64 | 62 |
/27 |
255.255.255.224 |
32 | 30 |
/28 |
255.255.255.240 |
16 | 14 |
/29 |
255.255.255.248 |
8 | 6 |
/30 |
255.255.255.252 |
4 | 2 |
/31 |
255.255.255.254 |
2 | Special case |
/32 |
255.255.255.255 |
1 | Single address |
The same block-size method works across octet boundaries.
For example, with a /20 mask:
Subnet mask = 255.255.240.0
Block size = 256 - 240
Block size = 16
The third-octet boundaries are:
0, 16, 32, 48, 64, 80...
An address such as:
172.16.37.10/20
falls inside the 32–47 block.
Its containing network is therefore:
172.16.32.0/20
and its broadcast address is:
172.16.47.255
The /31 exception
A /31 contains two addresses.
Under the traditional subnet rule, subtracting a network and broadcast address would leave no usable hosts. However, /31 networks can use both addresses as endpoints on a point-to-point link.
For example:
10.0.0.4/31
contains:
10.0.0.4
10.0.0.5
On an appropriately configured point-to-point link, both can be used as endpoint addresses.
Do not automatically treat /31 like a regular LAN subnet.
What does /32 mean?
A /32 identifies one exact IPv4 address:
203.0.113.25/32
It contains no additional addresses and is commonly used when a route, rule, or configuration must match a single host.
Calculate and verify it automatically
For quick checks, I built the Olivez IPv4 Subnet Calculator.
You can enter any IPv4 address with a prefix from /0 through /32, including an address that is not already the network boundary.
It calculates:
- Containing CIDR network
- Subnet mask
- Wildcard mask
- Broadcast address
- First and last usable addresses
- Total and usable address counts
- Address classification
- Binary network and host split
For example, entering:
192.168.1.130/26
returns the normalized network:
192.168.1.128/26
The calculator is useful for verifying manual work, but understanding the block-size method makes it much easier to spot incorrect CIDR ranges in routing tables, firewall rules, cloud networks, and infrastructure configuration.
A reusable calculation process
For any IPv4 address and prefix:
- Subtract the prefix from 32 to find the number of host bits.
- Calculate
2^host bitsto find the total number of addresses. - Convert the prefix to a subnet mask.
- Find the first mask octet that is not
255. - Calculate its block size using
256 - mask octet. - Find which block contains the entered address.
- Use the first address as the network boundary.
- Use the final address as the broadcast boundary.
- Exclude those two addresses for the traditional usable range.
- Handle
/31and/32as special cases.
Once you can identify the block boundary, the rest of the subnet becomes straightforward.
Top comments (0)