Guide
How to calculate an IPv4 subnet step by step
Learn how to obtain network, broadcast and host range from an IPv4 and a CIDR prefix, with a /27 example solved by hand.
by Tools in a Tab · Published on · Reviewed on
Short answer
Calculating an IPv4 subnet consists of separating the bits that identify the network from those that remain available within the block. With an address and a prefix CIDR you can get the network address, broadcast, first and last host and the number of addresses without depending on a memorized table.
Let’s solve 10.20.30.200/27 by hand. Then you can check the result
with the IPv4 subnet calculator.
Example result
| Field | Result |
|---|---|
| Input address | 10.20.30.200/27 |
| Mask | 255.255.255.224 |
| Network address | 10.20.30.192/27 |
| First regular host | 10.20.30.193 |
| Last regular host | 10.20.30.222 |
| Broadcast | 10.20.30.223 |
| Total addresses | 32 |
| Regular hosts | 30 |
The address entered does not have to be the first in the block. In this case,
.200 is an interior address of the subnet starting at .192.
Step 1: Interpret the /27 prefix
IPv4 has 32 bits. The number after the bar indicates how many bits make up the network part:
/27 = 27 network bits + 5 bits available inside the block
The mask places 27 ones in a row and fills in the remaining five bits with zeros:
11111111.11111111.11111111.11100000
255 .255 .255 .224
The first three octets contain 24 network bits. You just need to work with the last octet, where three network bits and five host bits remain.
Step 2: Calculate the block size
If five variable bits remain, there are 2⁵ combinations:
2^(32 - 27) = 2^5 = 32 direcciones
You can also get the jump by subtracting the last octet of the mask from 256:
256 - 224 = 32
Therefore, the blocks of the last octet start at 0, 32, 64, 96,
128, 160, 192 and 224.
Step 3: Locate the address block
The last octet of the IP is 200. It falls between block starts 192 and 224, so belongs to the block starting at 192. An equivalent way to calculate it is divide by the size, discard the decimals and multiply again:
floor(200 / 32) × 32 = 6 × 32 = 192
By retaining the first three octets, the network address is
10.20.30.192.
Step 4: calculate the broadcast
The next block starts at 10.20.30.224. The address immediately
above is the end of the current block:
224 - 1 = 223
The broadcast is 10.20.30.223. In binary, the network leaves the five host bits
to zero and the broadcast sets them all to one:
Network: 11000000 = 192
Broadcast: 11011111 = 223
This same result is obtained by applying a binary AND between IP and mask for the network and then activating all the bits available for the broadcast.
Step 5: Get the host range
In a conventional subnet, the network address and broadcast address are not assigned to hosts. The usual range is between the two:
Primer host: 10.20.30.192 + 1 = 10.20.30.193
Last host: 10.20.30.223 - 1 = 10.20.30.222
Of the 32 total addresses, 32 - 2 = 30 usual addresses remain
for interfaces.
Quick method for any prefix
- Convert the prefix to a mask.
- Identify the octet where the mask stops being 255.
- Calculate the block size with
256 - the value of that octet. - Find the multiple of the hop that does not exceed the IP octet.
- The network starts at that multiple and the broadcast ends just before the next.
- In subnets
/0to/30, add and subtract one to find the usual range of hosts.
When the prefix does not fall in the last octet, the principle is the same. By
For example, in a /20 the partial mask is 240 in the third octet and the jump
is 16 in that octet.
Prefixes that should be recognized
| Prefix | Mask | Directions | Regular 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 |
The common 2^(32 - prefix) - 2 host formula should not be applied without
nuances to /31 and /32.
Special cases: /31 and /32
A /31 contains exactly two addresses. In a point to point link,
both can identify the two ends and a broadcast is not reserved. This
Use is defined in RFC 3021.
A /32 contains a single address. Used as host path: does not provide a
range from which to remove network and broadcast.
Common errors when calculating subnets
- Round 200 to the nearest multiple instead of going down to the beginning of the block.
- Confuse the address entered with the network address.
- Subtract two addresses also in
/31or/32. - Accept masks with non-contiguous ones, such as
255.0.255.0. - Count the prefix from the right; CIDR counts network bits from left.
- Confuse total addresses with assignable addresses in the model conventional.
How to check your calculation
Enter 10.20.30.200 and /27 into the calculator. It should return network .192,
broadcast .223 and range .193–.222. If you are reviewing an exercise, repeat
calculation with binary or block size before accepting the result.
The tool works locally on the tab and does not check if the address is advertised, reserved or configured on a real network. Calculates exclusively the mathematical limits of the block.
Technical references
RFC 4632 describes CIDR, the
slash notation and IPv4 block sizes. RFC
3021 documents the treatment of
/31 prefixes on point-to-point links.