SUBNETTING EXPLAINED
Source: Dev.to
What is Subnetting?
Think of it like splitting a large apartment building into separate floors. Each floor (subnet) has its own numbered units (hosts), and the building’s address (network ID) identifies which floor you’re on.
IPv4 Address Structure
Example address: 192.168.1.10
Every IPv4 address is split into two logical parts:
- Network portion – determined by the subnet mask.
- Host portion – the remaining bits.
A /24 mask means the first 24 bits are the network portion and the last 8 bits are for hosts.
IP: 192.168.1.10
The Subnet Mask
255.255.255.0 = /24
Devices use the subnet mask to decide whether a destination IP is on the same local network (send directly) or on a different network (send to the gateway router).
How Devices Use the AND Operation
The rule is simple:
1 AND 1 = 1- Anything
AND 0 = 0
The result of the AND operation is the Network ID.
Source IP: 192.168.1.10
Binary: 11000000.10101000.00000001.00001010
Mask: 11111111.11111111.11111111.00000000
Result: 11000000.10101000.00000001.00000000 → 192.168.1.0 (Network ID)
The device performs this AND operation on both the source and destination IPs.
- If both results match, the devices are on the same subnet and communicate directly.
- If they differ, the packet is sent to the default gateway.
This logic is performed in hardware at wire speed on every packet.
Network ID and Broadcast Address
- Network ID – all host bits are
0. - Broadcast Address – all host bits are
1(the last address in the subnet).
Usable Host Addresses
Usable Hosts = 2^H − 2
where H is the number of host bits remaining after subnetting.
Example for /24
- H = 8 →
2^8 − 2 = 254usable hosts (addresses192.168.1.1–192.168.1.254).
Subnetting Formulas
- Number of subnets needed:
2^Nwhere N = bits borrowed from the host portion. - Hosts per subnet:
2^H − 2where H = remaining host bits.
You borrow N bits from the host portion of the original mask, which increases the prefix length by N. The remaining H bits define how many hosts each subnet can hold.
Borrowing Bits — What It Actually Means
Original network: 192.168.1.0/24
Borrow 2 bits:
11111111.11111111.11111111.11000000
- Borrowing 2 bits gives
2² = 4subnets. - Each subnet has
2^6 − 2 = 62usable hosts.
More subnets → fewer hosts per subnet. This is the fundamental trade‑off.
Block Size — The Most Useful Trick
Block Size = 256 − (interesting octet value)
The interesting octet is the octet where the subnet mask is neither 255 (fully network) nor 0 (fully host).
Example: /26
- Mask:
255.255.255.192 - Interesting octet value:
192 - Block Size:
256 − 192 = 64
Subnets start at: 0, 64, 128, 192
Memorize Common Block Sizes
| CIDR | Block Size |
|---|---|
| /25 | 128 |
| /26 | 64 |
| /27 | 32 |
| /28 | 16 |
| /29 | 8 |
| /30 | 4 |
These values appear in almost every subnetting problem.
Solving Subnet Problems — Step by Step
The 6‑Step Method
- Identify the prefix length (
/x) from the problem. - Find the interesting octet.
- Calculate the block size.
- List the subnet ranges.
- Determine which range contains the given host address.
- Read off the Network ID, Broadcast address, and usable host range.
Worked Example 1 — /26 Subnet
Problem: Given IP address 192.168.1.70/26, find the Network ID, Broadcast address, and usable host range.
| Step | Action |
|---|---|
| 1 | Prefix = /26 |
| 2 | Interesting octet = 4th octet (mask 192) |
| 3 | Block size = 256 − 192 = 64 |
| 4 | Subnet ranges: 0‑63, 64‑127, 128‑191, 192‑255 |
| 5 | 70 falls in the 64‑127 range |
| 6 | Network ID: 192.168.1.64Broadcast: 192.168.1.127Usable hosts: 192.168.1.65 – 192.168.1.126 |
Worked Example 2 — /22 Subnet
Problem: Given IP address 10.205.79.90/22, find the Network ID, Broadcast address, and host range.
| Step | Action |
|---|---|
| 1 | Prefix = /22 |
| 2 | Interesting octet = 3rd octet (mask 252) |
| 3 | Block size = 256 − 252 = 4 |
| 4 | Subnet ranges in the 3rd octet: 0‑3, 4‑7, 8‑11, …, 76‑79, 80‑83, … |
| 5 | 3rd octet 79 falls in the 76‑79 range |
| 6 | Network ID: 10.205.76.0Broadcast: 10.205.79.255Usable hosts: 10.205.76.1 – 10.205.79.254 |
When the interesting octet is not the last one (as in
/22), the full host range spans multiple values of the last octet. The network starts at(block_start).0and ends at(block_end).255.
Worked Example 3 — Subdividing a /24
Problem: A company has the network 192.168.1.0/24 and needs at least 3 subnets.
| Step | Action |
|---|---|
| 1 | Determine bits to borrow: need ≥3 subnets → borrow 2 bits (2² = 4 subnets) |
| 2 | New mask: /26 → 255.255.255.192 |
| 3 | List available subnets: 192.168.1.0/26, 192.168.1.64/26, 192.168.1.128/26, 192.168.1.192/26 |
Result: 4 subnets (one spare), each supporting 62 usable hosts. Assign three to departments and keep one as a spare.
CIDR Notation
192.168.1.0/24 means 24 network bits and 8 host bits.
CIDR (Classless Inter‑Domain Routing) is used everywhere—routing tables, firewall rules, cloud security groups, and IP allocation. Understanding /x notation instantly tells you the block size and host capacity of any subnet.
Quick Reference Table
| CIDR | Subnet Mask | Block Size | Total IPs | 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 |
Key Takeaways
- Subnetting divides one network into many by borrowing host bits – more subnets means fewer hosts per subnet.
- Devices find their subnet using bitwise AND:
IP AND Mask = Network ID. - The Network ID (all host bits
0) and Broadcast (all host bits1) are always reserved and never assignable to hosts. - Block size =
256 − mask octet value– the fastest tool for finding subnet ranges. - Usable hosts =
2^H − 2where H is the number of host bits. - CIDR
/xnotation tells you how many bits are network bits; everything else are host bits. - When designing subnets, prioritize the number of networks first, then the hosts per network.