Subnetting Step by Step: Masks, Block Sizes and VLSM
What is subnetting?
Subnetting is dividing one IP network into smaller networks, called subnets, by borrowing bits from the host portion of the address. Each subnet has its own network address, usable host range and broadcast address. Engineers subnet to match network sizes to real needs, separate departments or device types, limit broadcast traffic and apply security rules between groups.
Why networks are divided into subnets
A single flat network for every device works in a small home, but it causes problems as an organisation grows. Every broadcast reaches every device, faults are harder to isolate and there is no natural point to apply access rules. Subnetting solves this by creating several smaller networks joined by a router or layer 3 switch.
- Organisation: one subnet per department, floor, VLAN or device type such as cameras or printers.
- Security: traffic between subnets passes a router or firewall, where it can be filtered.
- Efficiency: addresses are not wasted, which matters for public IPv4 space.
- Performance: broadcasts stay inside their own subnet.
A subnet plan is usually written before any equipment is configured. It records each subnet, its purpose, its VLAN, its gateway address and how much room it has to grow. That plan then drives switch, router, firewall and DHCP configuration, so mistakes made on paper turn into outages later.
You should be comfortable with IPv4 structure first; the IP addressing guide covers octets, prefixes and private ranges.
Subnet masks, prefix lengths and the block size method
A subnet mask marks network bits with 1s and host bits with 0s. The prefix length is simply the count of 1s. For example, /26 means 26 network bits and 6 host bits.
/26 in binary: 11111111.11111111.11111111.11000000
/26 in decimal: 255 .255 .255 .192The block size method avoids most binary arithmetic. Find the interesting octet, the one where the mask is neither 255 nor 0. Subtract that mask value from 256 to get the block size. Subnets start at multiples of the block size in that octet.
The number of host bits, n, gives 2^n addresses per subnet. Subtract two for the network and broadcast addresses, so usable hosts equal 2^n minus 2. There are two exceptions: a /31 has two addresses that are both usable on point-to-point links (RFC 3021), and a /32 identifies a single host, often used for loopback interfaces and host routes.
Checking the answer in binary with the AND operation
The block size method is a shortcut for what a router actually does. To find the network an address belongs to, the device performs a bitwise AND between the address and the mask: wherever the mask has a 1 the address bit is kept, and wherever it has a 0 the result is 0. Setting every host bit to 1 instead gives the broadcast address.
Address 192.168.10.70 last octet: 01000110 (70)
Mask 255.255.255.192 last octet: 11000000 (192)
AND result (network) : 01000000 (64) -> 192.168.10.64
Host bits all set to 1 (broadcast): 01111111 (127) -> 192.168.10.127The result matches the block size method: with a block size of 64, the address 70 falls in the block that starts at 64 and ends at 127. When you are learning, work a few questions both ways. Once the binary version makes sense, you can trust the shortcut in exams and on the job, and you will understand why a wrong mask on one host makes it think a neighbour is on a different network.
Worked examples: four /26 subnets and a /20 address
Example 1: split 192.168.10.0/24 into four subnets
Four subnets need 2 borrowed bits (2 squared is 4), so the new prefix is /26 and the mask is 255.255.255.192. The block size is 256 minus 192, which is 64, leaving 6 host bits: 64 addresses and 62 usable hosts per subnet.
| Subnet | Network | First host | Last host | Broadcast |
|---|---|---|---|---|
| 1 | 192.168.10.0/26 | 192.168.10.1 | 192.168.10.62 | 192.168.10.63 |
| 2 | 192.168.10.64/26 | 192.168.10.65 | 192.168.10.126 | 192.168.10.127 |
| 3 | 192.168.10.128/26 | 192.168.10.129 | 192.168.10.190 | 192.168.10.191 |
| 4 | 192.168.10.192/26 | 192.168.10.193 | 192.168.10.254 | 192.168.10.255 |
Example 2: which subnet holds 172.16.45.200/20?
A /20 mask is 255.255.240.0, so the interesting octet is the third one with a block size of 256 minus 240, which is 16. Multiples of 16 in the third octet are 0, 16, 32, 48 and so on; 45 falls between 32 and 47. The network is 172.16.32.0, the first host is 172.16.32.1, the last host is 172.16.47.254 and the broadcast is 172.16.47.255. With 12 host bits, the subnet has 4,094 usable hosts.
Subnetting a network step by step
- Write down the starting network and the requirement: a number of subnets or a number of hosts per subnet.
- For a host requirement, find the smallest n where 2^n minus 2 is at least the host count; the prefix is 32 minus n.
- For a subnet-count requirement, find the smallest number of borrowed bits b where 2^b is at least the subnet count; add b to the original prefix.
- Convert the prefix to a mask and find the block size in the interesting octet.
- List the network addresses by counting up in block-size steps.
- For each subnet, the first host is the network plus one, the broadcast is the next network minus one, and the last host is the broadcast minus one.
- Check your work: the last broadcast must equal the broadcast of the original network.
VLSM: different subnet sizes from one block
Variable Length Subnet Masking (VLSM) lets you give each segment a prefix that fits its size. Allocate the largest subnet first so each block starts on a correct boundary. Suppose you have 172.16.0.0/24 for a sales LAN of 100 hosts, an engineering LAN of 50 hosts, an admin LAN of 20 hosts and two router-to-router links.
| Segment | Need | Prefix | Network | Usable range | Broadcast |
|---|---|---|---|---|---|
| Sales | 100 hosts | /25 (126 hosts) | 172.16.0.0 | .1 to .126 | 172.16.0.127 |
| Engineering | 50 hosts | /26 (62 hosts) | 172.16.0.128 | .129 to .190 | 172.16.0.191 |
| Admin | 20 hosts | /27 (30 hosts) | 172.16.0.192 | .193 to .222 | 172.16.0.223 |
| Link A | 2 hosts | /30 (2 hosts) | 172.16.0.224 | .225 to .226 | 172.16.0.227 |
| Link B | 2 hosts | /30 (2 hosts) | 172.16.0.228 | .229 to .230 | 172.16.0.231 |
Addresses 172.16.0.232 to 172.16.0.255 remain free for later growth. Routers advertise these subnets as described in routing and switching basics.
Quick reference: /24 to /30
| Prefix | Mask | Block size | Addresses | Usable hosts |
|---|---|---|---|---|
| /24 | 255.255.255.0 | 256 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 16 | 14 |
| /29 | 255.255.255.248 | 8 | 8 | 6 |
| /30 | 255.255.255.252 | 4 | 4 | 2 |
Good practice is to leave room for growth, document every subnet with its VLAN and gateway, and use the first or last usable address consistently for the gateway.
Practical exercise: answer five subnetting questions
Work each question on paper using the block size method, then check your answer.
- Which subnet does
10.1.1.70/27belong to? Answer: block size 32, so network10.1.1.64, hosts.65to.94, broadcast10.1.1.95. - How many usable hosts are in a
/28? Answer: 4 host bits, so 16 minus 2, which is 14. - What is the broadcast address of
192.168.5.130/25? Answer: block size 128, network192.168.5.128, broadcast192.168.5.255. - What is the longest prefix that still holds 500 hosts? Answer: 9 host bits give 510 usable hosts, so
/23with mask255.255.254.0. - Split
10.20.0.0/24into eight equal subnets. Answer: 3 borrowed bits give/27, networks at.0,.32,.64,.96,.128,.160,.192and.224, each with 30 usable hosts.
You are done when you can answer all five without a calculator and explain each step aloud. Then design a VLSM plan for your own lab, and see the Networking Foundation course if you want guided subnetting practice.
Common mistakes
- Counting the network and broadcast addresses as usable hosts.
- Allocating small VLSM subnets before large ones, which leaves blocks starting on invalid boundaries.
- Using 256 minus the wrong octet, such as the 255 octet, when finding the block size.
- Forgetting that the host formula 2^n minus 2 does not apply to
/31point-to-point links. - Leaving no spare address space, so the network must be renumbered when it grows.
Frequently asked questions
Is subnetting still needed with IPv6?
Yes, but it works differently. LAN segments normally use a /64, and planning is about splitting a larger allocation such as a /48 or /56 into /64 networks rather than conserving host addresses.
What is the difference between subnetting and VLANs?
A VLAN separates devices at layer 2 on a switch, while a subnet separates them at layer 3 by IP address. In practice each VLAN is usually given its own subnet and gateway.
What is supernetting?
Supernetting, or route summarisation, combines several contiguous networks into one shorter prefix. For example, 192.168.0.0/24 to 192.168.3.0/24 can be summarised as 192.168.0.0/22, which keeps routing tables smaller.
Should I use a subnet calculator?
A calculator is useful for checking a finished design or documenting a large plan. Learn to work the answers by hand first, though, because certification exams expect it and fault-finding on a live network is much faster when you can spot a wrong mask or gateway at a glance.