NetworkingConcept

How to subnet an IPv4 network

About 12 minutes. Updated .

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.

PrefixMaskAddressesUsable hosts
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/29255.255.255.24886
/30255.255.255.25242
/31255.255.255.25422
/32255.255.255.25511

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 octet12345678
Mask octet128192224240248252254255
Block size1286432168421

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 calculator

172.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 calculator

Step 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

ExampleNetworkFirst usableLast usableBroadcastHosts
192.0.2.37/26192.0.2.0192.0.2.1192.0.2.62192.0.2.6362
172.16.45.200/20172.16.32.0172.16.32.1172.16.47.254172.16.47.2554,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.

#SubnetUsable rangeBroadcast
1198.51.100.0/26198.51.100.1 – 198.51.100.62198.51.100.63
2198.51.100.64/26198.51.100.65 – 198.51.100.126198.51.100.127
3198.51.100.128/26198.51.100.129 – 198.51.100.190198.51.100.191
4198.51.100.192/26198.51.100.193 – 198.51.100.254198.51.100.255
Try this split in the calculator

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

  • /31 has only two addresses. On a point-to-point link both are usable and there is no broadcast (RFC 3021): 203.0.113.4/31 gives hosts 203.0.113.4 and 203.0.113.5.
  • /32 is 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 calculator
2192.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 calculator
310.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 calculator

Adapted 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.