Here in this blog i made complete guide to IP subnetting — from theory to practical problem solving. Let's Start
1. What is Subnetting?
Subnetting is the process of dividing one large IP network into multiple smaller, logical subnetworks (subnets). This is done by borrowing bits from the host portion of an IP address and assigning them to the network portion — effectively shrinking each network's host space to create more networks.
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.
Why Do We Subnet?
•Efficient IP address usage — avoid wasting large blocks of addresses on small networks
•Reduce broadcast traffic — broadcasts stay confined within each subnet
•Improve performance — less unnecessary traffic on each segment
•Better security segmentation — isolate departments or systems
•Easier network management — logical groupings make troubleshooting simpler
2. IPv4 Address Structure
An IPv4 address is 32 bits long, written in dotted-decimal notation — four groups of 8 bits (called octets), each ranging from 0 to 255.
Example: 192.168.1.10
Binary: 11000000.10101000.00000001.00001010
Every IPv4 address is split into two logical parts:
•Network bits — identify which network the device belongs to
•Host bits — identify the specific device within that network
The subnet mask determines where the boundary between network bits and host bits falls. 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
Mask: 255.255.255.0 (/24)
|--Network----|Host|
3. The Subnet Mask
The subnet mask is a 32-bit number that tells both routers and hosts which part of an IP address is the network ID and which part is the host ID. In binary, it is always a sequence of 1s followed by 0s — no mixing.
255.255.255.0 = /24
11111111.11111111.11111111.00000000
1s = network bits 0s = host bits
Devices use the subnet mask to decide whether a destination IP is on the same local network (send directly) or a different network (send to the gateway router).
4. How Devices Use the AND Operation
When a device wants to communicate with another IP address, it needs to determine if that address is on the same subnet. It does this using a bitwise AND operation — comparing each bit of the IP address against the corresponding bit of the subnet mask.
The rule is simple: 1 AND 1 = 1, anything AND 0 = 0. The result is the Network ID.
Source IP: 192.168.1.10
Subnet Mask: 255.255.255.0
IP: 11000000.10101000.00000001.00001010
Mask: 11111111.11111111.11111111.00000000
AND: 11000000.10101000.00000001.00000000
Result: 192.168.1.0 (this is the Network ID)
The device performs this AND operation on BOTH the source and destination IPs. If both results match, they are on the same subnet — communicate directly. If they differ, the packet goes to the default gateway.
This AND logic is performed in hardware at wire speed — it happens on every single packet a device sends or receives.
5. Network ID and Broadcast Address
Network ID (First Address)
The Network ID is the address where all host bits are set to 0. It identifies the subnet itself — you cannot assign this address to any device.
192.168.1.0/24 → Host bits = 00000000 → Network ID
Broadcast Address (Last Address)
The broadcast address is where all host bits are set to 1. Any packet sent to this address is delivered to every device on the subnet. You cannot assign this address to any device either.
192.168.1.255/24 → Host bits = 11111111 → Broadcast
6. Usable Host Addresses
Since the first address (Network ID) and the last address (Broadcast) in any subnet are reserved and cannot be assigned to hosts, the formula for usable hosts is:
Usable Hosts = 2^H − 2
Where H = the number of host bits remaining after subnetting.
Example for /24:
Host bits (H) = 32 - 24 = 8
Usable hosts = 2^8 - 2 = 256 - 2 = 254
Range: 192.168.1.1 to 192.168.1.254
7. Subnetting Formulas
Two core formulas drive every subnetting decision:
For number of subnets needed:
2^N ≥ required subnets (N = bits to borrow)
For hosts per subnet:
2^H − 2 ≥ required hosts (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.
8. Borrowing Bits — What It Actually Means
When you "borrow" bits, you are shifting the boundary between network and host portions further into the host space. This creates more network addresses (subnets) but reduces the host space in each one.
Original network: 192.168.1.0/24
Original mask: 11111111.11111111.11111111.00000000
Borrow 2 bits: 11111111.11111111.11111111.11000000
New mask: 255.255.255.192 (/26)
Borrowing 2 bits gives us 2² = 4 subnets, each with 2^6 − 2 = 62 usable hosts. More subnets, fewer hosts per subnet — that's the fundamental trade-off.
9. Block Size — The Most Useful Trick
The block size tells you how many IP addresses each subnet contains (including Network ID and Broadcast). It's the increment between subnet starting addresses, and it makes finding subnet ranges fast without binary math.
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) — it is the octet being split.
Example: /26 → Mask = 255.255.255.192
Interesting octet value = 192
Block size = 256 - 192 = 64
Subnets start at: 0, 64, 128, 192
-->Memorize block sizes: /25→128, /26→64, /27→32, /28→16, /29→8, /30→4. These come up in every subnetting problem.
10. Solving Subnet Problems — Step by Step
This is where most people get stuck. The key is following a repeatable process every single time. Here is the universal method with full explanation of each step.
The 6-Step Method
1.Identify the prefix length (/x) from the problem
2.Determine the interesting octet (where the split happens)
3.Calculate the block size: 256 − mask value in that octet
4.List the subnet ranges by adding block size repeatedly
5.Find which range your IP falls into
6.Read off Network ID (first), Broadcast (last), and host range (between)
Worked Example 1 — /26 subnet
Problem: Given IP address 192.168.1.70/26, find the Network ID, Broadcast, and usable host range.
Step 1 — Identify the prefix
/26 → 26 network bits, 6 host bits
Step 2 — Find the interesting octet
Mask for /26: 255.255.255.192
Octets 1,2,3 = 255 (fully network — not interesting)
Octet 4 = 192 (this is the interesting octet)
Step 3 — Calculate block size
Block size = 256 - 192 = 64
Step 4 — List the subnet ranges
Subnet 1: 0 to 63
Subnet 2: 64 to 127 ← our IP (70) falls here
Subnet 3: 128 to 191
Subnet 4: 192 to 255
Step 5 — Confirm which range contains 70
70 is between 64 and 127, so we are in the second subnet.
Step 6 — Read off the answers
Network ID: 192.168.1.64 (first address in range)
Broadcast: 192.168.1.127 (last address in range)
First host: 192.168.1.65
Last host: 192.168.1.126
Usable hosts: 62 (2^6 - 2)
Worked Example 2 — /22 subnet
Problem: Given IP address 10.205.79.90/22, find the Network ID, Broadcast, and host range.
Step 1 — Identify the prefix
/22 → 22 network bits, 10 host bits
Step 2 — Find the interesting octet
Mask for /22: 255.255.252.0
Octet 1 = 255, Octet 2 = 255 (not interesting)
Octet 3 = 252 (this is the interesting octet!)
Octet 4 = 0 (fully host — not interesting)
Step 3 — Calculate block size
Block size = 256 - 252 = 4
Step 4 — List subnet ranges in the 3rd octet
...72-75, 76-79, 80-83, 84-87...
Step 5 — The 3rd octet of our IP is 79
79 falls in the range 76–79. So the network starts at 76 in the third octet.
Step 6 — Read off the answers
Network ID: 10.205.76.0 (3rd octet = 76, 4th = 0)
Broadcast: 10.205.79.255 (3rd octet = 79, 4th = 255)
First host: 10.205.76.1
Last host: 10.205.79.254
Usable hosts: 1022 (2^10 - 2)
When the interesting octet is not the last one (like /22), the full host range spans multiple values of the last octet. The network starts at (block_start).0 and ends at (block_end).255.
Worked Example 3
Problem: A company has the network 192.168.1.0/24 and needs to divide it into at least 3 departments.
Step 1 — Find how many bits to borrow
We need 3 subnets
2^1 = 2 (not enough)
2^2 = 4 (enough — borrow 2 bits)
Step 2 — Calculate the new mask
Original: /24
Borrow 2 bits → /24 + 2 = /26
New mask: 255.255.255.192
Step 3 — List the available subnets
Subnet 1: 192.168.1.0/26 Hosts: .1 to .62
Subnet 2: 192.168.1.64/26 Hosts: .65 to .126
Subnet 3: 192.168.1.128/26 Hosts: .129 to .190
Subnet 4: 192.168.1.192/26 Hosts: .193 to .254 (spare)
You now have 4 subnets (we needed 3 minimum), each supporting 62 hosts. Assign three to departments and keep one as a spare.
11. CIDR Notation
CIDR (Classless Inter-Domain Routing) notation is the compact /x format that replaces the older class-based system. Instead of writing out the full subnet mask, you write the number of network bits after a slash.
192.168.1.0/24 means 24 network bits, 8 host bits
10.0.0.0/8 means 8 network bits, 24 host bits
172.16.0.0/12 means 12 network bits, 20 host bits
CIDR 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.
12. 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
13. Key Takeaways
Here is everything you need to carry away from this guide:
•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 bits = 1) are always reserved — never assignable
•Block size = 256 − mask octet value — this is your fastest tool for finding subnet ranges
•Usable hosts = 2^H − 2 where H is the number of host bits
•CIDR /x notation tells you how many bits are network bits — everything else is host bits
•When designing subnets, always prioritize number of networks first, then hosts per network.
Top comments (0)