How to subnet an IPv4 network
Subnetting is working out where one network ends and the next begins. Do it by hand once and the calculator’s answers
stop being magic. You need an address with a prefix, like 192.0.2.37/26, and the powers of two up to 256.
The idea in one picture
An IPv4 address is 32 bits, written as four numbers of 8 bits each (octets). The prefix — the /26 — says how many bits,
counted from the left, name the network. The bits that are left number the hosts on that network.
192.0.2.37/26 in binary: the first 26 bits (blue) are the network, the last 6 (orange) are
the host. Every address that shares those first 26 bits is on the same network.
Everything below is arithmetic on that split. You never need to write out all 32 bits; one octet is enough.
Step 1: Read the prefix and the mask
The mask is the prefix written as an address: 26 ones followed by 6 zeros. In dotted form that
is 255.255.255.192. Both say the same thing, so learn to read either.
| Prefix | Mask | Addresses | 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 | 2 |
| /32 | 255.255.255.255 | 1 | 1 |
Shorter prefixes repeat the pattern one octet further left: /16 is 255.255.0.0 and /20 is
255.255.240.0. Only eight values ever appear in a mask octet:
| Network bits in the octet | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Mask octet | 128 | 192 | 224 | 240 | 248 | 252 | 254 | 255 |
| Block size | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Step 2: Find the block size
In every mask exactly one octet is neither 255 nor 0 (unless the prefix is a multiple of 8). That is the interesting octet: the one where the network ends. Subtract it from 256 to get the block size — how far apart the networks are.
block size = 256 − 192 = 64
For /26 the interesting octet is the fourth one, so networks start every 64 addresses there: .0, .64,
.128 and .192. For /20 it is the third octet (240), so networks start every 16 in that
octet.
Step 3: Find the network address
Round the interesting octet of the address down to a multiple of the block size. Octets to its left stay as they are; octets to its right become 0.
192.0.2.37/26: block size 64 in the fourth octet, which is 37. The nearby multiples of 64 are 0, 64; 37 rounds down to 0.
network = 192.0.2.0/26
Check 192.0.2.37/26 in the calculator172.16.45.200/20: block size 16 in the third octet, which is 45. The nearby multiples of 16 are 16, 32, 48; 45 rounds down to 32, and the octets after it become 0.
network = 172.16.32.0/20
Check 172.16.45.200/20 in the calculatorStep 4: Find the broadcast and the usable hosts
The next network starts one block later. The broadcast is the address just before it, and the usable hosts are everything between the network and the broadcast.
usable hosts = 26 − 2 = 62
| Example | Network | First usable | Last usable | Broadcast | Hosts |
|---|---|---|---|---|---|
| 192.0.2.37/26 | 192.0.2.0 | 192.0.2.1 | 192.0.2.62 | 192.0.2.63 | 62 |
| 172.16.45.200/20 | 172.16.32.0 | 172.16.32.1 | 172.16.47.254 | 172.16.47.255 | 4,094 |
For the /20: the next network is 172.16.48.0, so the broadcast is the address before it,
172.16.47.255. The minus 2 in the formula is the network and broadcast addresses, which no host can use.
Step 5: Split a network into subnets
To cut a network into equal pieces, move the boundary right: every host bit you borrow doubles the number of subnets.
4 subnets need 2 bits, so 198.51.100.0/24 becomes 4 × /26.
| # | Subnet | Usable range | Broadcast |
|---|---|---|---|
| 1 | 198.51.100.0/26 | 198.51.100.1 – 198.51.100.62 | 198.51.100.63 |
| 2 | 198.51.100.64/26 | 198.51.100.65 – 198.51.100.126 | 198.51.100.127 |
| 3 | 198.51.100.128/26 | 198.51.100.129 – 198.51.100.190 | 198.51.100.191 |
| 4 | 198.51.100.192/26 | 198.51.100.193 – 198.51.100.254 | 198.51.100.255 |
Not a power of two? Round up: 5 subnets need 3 bits, which gives 8
subnets of /27.
Groups of different sizes (200 guests, 25 servers…) need subnets of different sizes. That is VLSM, and Subnet Sketch plans it for you, largest first.
Two special cases: /31 and /32
/31has only two addresses. On a point-to-point link both are usable and there is no broadcast (RFC 3021):203.0.113.4/31gives hosts203.0.113.4and203.0.113.5./32is a single address,192.0.2.77. It names one host, for example a loopback or a host route.
Address classes are history
Old material sorts addresses into classes by the first octet: A (1–126, /8), B (128–191, /16), C (192–223, /24). CIDR replaced classes in 1993 (RFC 1519, today RFC 4632), and every method above works for any prefix. Exams still ask about classes; networks don’t use them.
Practice
Find the network, the usable range and the broadcast. Open an answer when you’re done.
1203.0.113.77/28
Interesting octet: the fourth, block size 16. 77 rounds down to 64.
network 203.0.113.64, hosts 203.0.113.65 – 203.0.113.78, broadcast 203.0.113.79, 14 usable
Check 203.0.113.77/28 in the calculator2192.0.2.130/25
Interesting octet: the fourth, block size 128. 130 rounds down to 128.
network 192.0.2.128, hosts 192.0.2.129 – 192.0.2.254, broadcast 192.0.2.255, 126 usable
Check 192.0.2.130/25 in the calculator310.44.203.9/21
Interesting octet: the third, block size 8. 203 rounds down to 200.
network 10.44.200.0, hosts 10.44.200.1 – 10.44.207.254, broadcast 10.44.207.255, 2,046 usable
Check 10.44.203.9/21 in the calculatorAdapted from subnetting notes I wrote for a network administration course in 2021, rewritten for this site. The numbers on this page are computed by the same tested code as the calculator.