LEARN · Subnetting

SUBNETTING BY HAND

By Richard Lucht · Published

Every subnetting question asks the same thing in a different way: given an address and a prefix, where does this subnet start, where does it end, and how big is it? You can answer all of it without writing a single binary digit. The trick is the block size: subnets of a given size always start on multiples of their block size, so finding a network is just rounding down.

This guide walks through the method, explains why it works, and solves four examples in different octets.

Why block sizes work

An IPv4 address is 32 bits, shown as four octets of 8 bits each. The prefix length says how many of those bits, counted from the left, belong to the network. The rest are host bits. A /26 has 26 network bits and 6 host bits.

All the host bits set to 0 gives the network address. All of them set to 1 gives the broadcast. Because the host bits are always the low-order bits, every subnet covers a contiguous range of addresses whose size is a power of two, and every subnet starts on a multiple of that size. That size, counted in the octet where the prefix ends, is the block size.

The method in three steps

  1. Find the interesting octet. A prefix from /1 to /8 ends in the first octet, /9 to /16 in the second, /17 to /24 in the third and /25 to /32 in the fourth. Octets to the left are copied from the address unchanged.
  2. Get the block size. Subtract the mask value in the interesting octet from 256. The eight possible mask values and their block sizes are below.
  3. Round down, then add a block. Round the interesting octet down to a multiple of the block size to get the network. Add one block to get the next network. The broadcast is one address before that.
Mask value Bits in the octet Block size
128 1 128
192 2 64
224 3 32
240 4 16
248 5 8
252 6 4
254 7 2
255 8 1

Octets to the right of the interesting octet are always 0 in the network address and 255 in the broadcast.

Example 1: a /29 in the fourth octet

Address: 192.168.44.201/29

A /29 ends in the fourth octet with a mask of 248, so the block size is 256 − 248 = 8. Subnets start at .0, .8, .16 and so on. The largest multiple of 8 at or below 201 is 200.

The address in the question happens to be the first usable host. That’s common in exams, and it’s a good reminder to check rather than assume the given address is somewhere in the middle.

Example 2: a /19 in the third octet

Address: 172.31.130.9/19

A /19 ends in the third octet. The mask is 255.255.224.0, so the block size is 256 − 224 = 32 in the third octet. Multiples of 32 are 0, 32, 64, 96, 128 and 160. 130 rounds down to 128.

The fourth octet of the original address (9) plays no part. Once the interesting octet is to its left, it’s always 0 in the network and 255 in the broadcast.

Example 3: a /10 in the second octet

Address: 100.70.5.5/10

A /10 ends in the second octet with a mask of 255.192.0.0, so the block size is 64. 70 rounds down to 64.

You may recognize 100.64.0.0/10. It’s the shared address space reserved by RFC 6598 for carrier-grade NAT, which is why some ISPs hand out WAN addresses starting with 100.64 to 100.127.

Example 4: are two hosts on the same subnet?

Question: a server is 10.1.1.120/25 and its gateway is 10.1.1.130. Will it work?

A /25 has a block size of 128 in the fourth octet, so the two subnets in 10.1.1.0 are .0 to .127 and .128 to .255. The server’s network is 10.1.1.0. The gateway’s address, with the same /25, falls in 10.1.1.128. They’re on different subnets, so the server can’t reach its own gateway and has no route off the subnet. Either the mask is wrong (a /24 would put both in 10.1.1.0) or the gateway address is.

This is the most useful everyday form of the skill. A misconfigured mask is one of the classic causes of “it can ping some things but not others.”

Common mistakes

Building speed

Speed comes from not having to think about the eight mask values. Write them out from memory a few times (128, 192, 224, 240, 248, 252, 254, 255) and say the block sizes next to them. Then practice on real addresses: each day’s Subnetle puzzle is a fresh address in a random octet, and the feedback arrows tell you which way you went wrong.

Practice it: Subnetle puts this into a daily game, free in your browser.

FAQ

Do I need to learn binary to subnet?

It helps to understand why the method works, but you don't need to convert addresses to binary to get answers. Block sizes are powers of two, and once you know the eight mask values (128, 192, 224, 240, 248, 252, 254, 255) you can solve any subnet with subtraction and rounding.

What is the last usable address?

The broadcast address minus one. In 192.168.44.200/29 the broadcast is .207, so the last usable host is .206.

How do I tell if two addresses are in the same subnet?

Work out the network address for each one using the same prefix. If the networks match, the addresses share a subnet and can talk without a router. If they differ, traffic between them has to be routed.

Is the block size the same as the number of hosts?

Only when the prefix ends in the fourth octet. A /27 has a block size of 32 and holds 32 addresses. A /19 has a block size of 32 in the third octet, which means 32 × 256 = 8,192 addresses.

SOURCES

RELATED GUIDES