Loading learning content...
IP subnetting is arguable the most frequently tested numerical skill in networking interviews. Whether you're facing a CCNA exam, a cloud architecture interview, or designing a real enterprise network, the ability to quickly and accurately calculate subnets, host ranges, and address allocations is essential.
Why subnetting matters: Every device on the internet needs an IP address. Efficient allocation of addresses determines how well a network scales, how routing tables grow, and how security policies can be applied. Poor subnetting leads to address exhaustion, routing inefficiency, and administratively painful renumbering projects.
By the end of this page, you will: (1) Convert between binary, decimal, and CIDR notation rapidly, (2) Calculate network addresses, broadcast addresses, and host ranges, (3) Apply Variable Length Subnet Masking (VLSM) for efficient address allocation, (4) Design hierarchical addressing schemes, and (5) Solve complex subnetting interview problems under time pressure.
Before solving subnetting problems, you need rock-solid fundamentals in IP address structure.
An IPv4 address is a 32-bit binary number, typically written as four decimal octets separated by dots:
192.168.1.100 = 11000000.10101000.00000001.01100100
^ ^
Decimal Binary (actual format)
Every octet ranges from 0-255 (2^8 values). The total address space is 2^32 = 4,294,967,296 addresses.
The subnet mask divides the IP address into two parts:
| Mask (Decimal) | Mask (Binary) | CIDR | Host Bits | Hosts |
|---|---|---|---|---|
| 255.0.0.0 | 11111111.00000000.00000000.00000000 | /8 | 24 | 16,777,214 |
| 255.255.0.0 | 11111111.11111111.00000000.00000000 | /16 | 16 | 65,534 |
| 255.255.255.0 | 11111111.11111111.11111111.00000000 | /24 | 8 | 254 |
| 255.255.255.128 | 11111111.11111111.11111111.10000000 | /25 | 7 | 126 |
| 255.255.255.192 | 11111111.11111111.11111111.11000000 | /26 | 6 | 62 |
| 255.255.255.224 | 11111111.11111111.11111111.11100000 | /27 | 5 | 30 |
| 255.255.255.240 | 11111111.11111111.11111111.11110000 | /28 | 4 | 14 |
| 255.255.255.248 | 11111111.11111111.11111111.11111000 | /29 | 3 | 6 |
| 255.255.255.252 | 11111111.11111111.11111111.11111100 | /30 | 2 | 2 |
Usable hosts = 2^n - 2, where n = host bits. We subtract 2 because the first address (all zeros in host portion) is the network address, and the last address (all ones) is the broadcast address. Neither can be assigned to hosts. Exception: /31 and /32 for point-to-point links (RFC 3021).
Subnetting speed depends on instant recall of powers of 2 and quick binary-decimal conversion.
| Power | Value | CIDR Hosts | Subnet Mask Octet |
|---|---|---|---|
| 2^0 | 1 | /32 → 1 (host route) | 255 |
| 2^1 | 2 | /31 → 2 (point-to-point) | 254 |
| 2^2 | 4 | /30 → 2 usable | 252 |
| 2^3 | 8 | /29 → 6 usable | 248 |
| 2^4 | 16 | /28 → 14 usable | 240 |
| 2^5 | 32 | /27 → 30 usable | 224 |
| 2^6 | 64 | /26 → 62 usable | 192 |
| 2^7 | 128 | /25 → 126 usable | 128 |
| 2^8 | 256 | /24 → 254 usable | 0 (next octet) |
A powerful shortcut: Subnet boundaries occur at intervals of the block size, which is: $$Block\ Size = 256 - Subnet\ Mask\ Octet$$
For example:
This means:
/25 = 128, /26 = 64, /27 = 32, /28 = 16, /29 = 8, /30 = 4. For any address, find which block it falls into by dividing the interesting octet by the block size. 192.168.1.100 with /26 (block 64): 100/64 = 1.xx → Block 1 → Subnet starts at 64.
Given an IP address and subnet mask, you should be able to instantly determine:
Address: 192.168.5.130
Mask: /26 = 255.255.255.192Step 1: Block size = 256 - 192 = 64
Step 2: Find subnet boundary
130 / 64 = 2.03 → Subnet index = 2
Subnet starts at: 2 × 64 = 128
Step 3: Calculate all addresses
• Network: 192.168.5.128/26
• First host: 192.168.5.129
• Last host: 192.168.5.190
• Broadcast: 192.168.5.191
• Next subnet: 192.168.5.192
Step 4: Host count
Host bits = 32 - 26 = 6
Usable hosts = 2^6 - 2 = **62**The address 192.168.5.130 falls in the subnet 192.168.5.128/26. This subnet's range spans from .128 to .191. The host .130 is the third usable address in this subnet.
Address: 10.45.137.200
Mask: /20 = 255.255.240.0Step 1: /20 affects the third octet
Mask octet value = 240
Block size = 256 - 240 = 16
Step 2: Find subnet in third octet
137 / 16 = 8.56 → Subnet index = 8
Third octet starts at: 8 × 16 = 128
Step 3: Calculate addresses
• Network: 10.45.128.0/20
• Broadcast: 10.45.143.255 (128 + 15 = 143 in third octet, then .255)
• Host range: 10.45.128.1 to 10.45.143.254
Step 4: Hosts
Host bits = 32 - 20 = 12
Usable hosts = 2^12 - 2 = **4,094**When the mask doesn't fall on an octet boundary (not /8, /16, or /24), the 'interesting octet' is where the mask transitions. For /20, that's the third octet. The fourth octet has full host bits (0-255).
VLSM allows different subnets within the same network to have different sizes, enabling efficient address allocation. Without VLSM, all subnets must be the same size, wasting addresses.
Given: 192.168.10.0/24 to allocate for:
Available: 192.168.10.0/24 (256 addresses)
Dept A: 100 hosts → need /25 (128 - 2 = 126 ≥ 100)
Dept B: 50 hosts → need /26 (64 - 2 = 62 ≥ 50)
Dept C: 25 hosts → need /27 (32 - 2 = 30 ≥ 25)
Servers: 10 hosts → need /28 (16 - 2 = 14 ≥ 10)
P2P: 2 hosts each → need /30 (4 - 2 = 2)**Allocation (largest first):**
1. Dept A (100 hosts): 192.168.10.0/25
Range: .0 - .127, usable: .1 - .126
Next available: 192.168.10.128
2. Dept B (50 hosts): 192.168.10.128/26
Range: .128 - .191, usable: .129 - .190
Next available: 192.168.10.192
3. Dept C (25 hosts): 192.168.10.192/27
Range: .192 - .223, usable: .193 - .222
Next available: 192.168.10.224
4. Servers (10 hosts): 192.168.10.224/28
Range: .224 - .239, usable: .225 - .238
Next available: 192.168.10.240
5. P2P Links:
Link 1: 192.168.10.240/30 (.240-.243)
Link 2: 192.168.10.244/30 (.244-.247)
Link 3: 192.168.10.248/30 (.248-.251)
Link 4: 192.168.10.252/30 (.252-.255)
**Total used: 256 addresses (100%)**VLSM enables perfect fit allocation. Without VLSM, using /25 for all would require 5 × 128 = 640 addresses (multiple /24s). With VLSM, we fit everything in a single /24. The key is allocating largest-first to avoid fragmentation.
The most common VLSM mistake is allocating overlapping address ranges. Always calculate the broadcast address of the current allocation before starting the next. For example, if you allocate 192.168.10.0/25, the next available address is .128, not .127 (which is the broadcast).
While subnetting divides a network into smaller pieces, supernetting (or route aggregation/summarization) combines multiple contiguous networks into a single larger block. This is essential for keeping routing tables manageable.
Networks can be summarized into a single route if:
To aggregate N networks of size /X: $$Aggregate\ prefix = X - log_2(N)$$
For example: 4 × /24 networks → /24 - log₂(4) = /24 - 2 = /22
192.168.16.0/24
192.168.17.0/24
192.168.18.0/24
192.168.19.0/24Step 1: Verify contiguity
16, 17, 18, 19 are contiguous ✓
Step 2: Count and power check
4 networks = 2^2 ✓
Step 3: Check divisibility
16 / 4 = 4.0 (exactly divisible) ✓
Step 4: Calculate aggregate
Original: /24
Combining: 4 = 2^2
Aggregate: /24 - 2 = /22
Step 5: Verify the summary
192.168.16.0/22 covers:
.16.0 - .19.255 (4 × 256 = 1024 addresses) ✓
**Summary route: 192.168.16.0/22**By advertising a single /22 instead of four /24s, customers can be summarized into a single routing table entry. This is how ISPs keep their routing tables manageable despite millions of customer networks.
10.10.32.0/24
10.10.33.0/24
10.10.34.0/24
10.10.35.0/24
10.10.36.0/24
10.10.37.0/24Step 1: Count = 6 networks (not a power of 2)
Cannot aggregate all 6 directly
Step 2: Find aggregatable groups
• 32-35: 4 networks, 32/4 = 8 (divisible)
→ 10.10.32.0/22 ✓
• 36-37: 2 networks, 36/2 = 18 (divisible)
→ 10.10.36.0/23 ✓
**Best aggregation:**
10.10.32.0/22 (covers 32-35)
10.10.36.0/23 (covers 36-37)
Reduced from 6 routes to 2 routesWhen the network count isn't a power of 2, you must find the largest possible aggregates. Here, we reduced 6 routes to 2. Perfect aggregation requires careful address planning—this is why network architects allocate contiguous blocks to regions or customers.
IPv6 subnetting follows the same principles as IPv4 but with much larger address space and different conventions.
| Address Part | Bits | Typical Prefix | Purpose |
|---|---|---|---|
| Global Routing Prefix | 48 | /48 | Identifies organization |
| Subnet ID | 16 | Local subnet within org | |
| Interface ID | 64 | Device identifier |
Standard allocation: /48 per site
End-user typically gets: /56 or /48
Given: 2001:db8:abcd::/48 Available subnets: 2001:db8:abcd:0000::/64 through 2001:db8:abcd:ffff::/64 That's 65,536 /64 subnets!
| Subnet | Address Range |
|---|---|
| 2001:db8:abcd:0000::/64 | ...::0000:0:0:0:0 to ...::0000:ffff:ffff:ffff:ffff |
| 2001:db8:abcd:0001::/64 | ...::0001:0:0:0:0 to ...::0001:ffff:ffff:ffff:ffff |
| 2001:db8:abcd:cafe::/64 | ...::cafe:0:0:0:0 to ...::cafe:ffff:ffff:ffff:ffff |
| 2001:db8:abcd:ffff::/64 | Last subnet in the allocation |
IPv6 subnetting is actually simpler than IPv4 because: (1) No NAT means every device gets a public address, (2) /64 for all regular subnets (no calculations needed), (3) Abundant space means you never worry about host counts, (4) Nibble-aligned subnets (at 4-bit boundaries) are easy to read and remember.
Certain IP address ranges have special meanings. You must know these for interviews and real-world network design.
| Range | CIDR | Purpose | Routable? |
|---|---|---|---|
| 0.0.0.0/8 | /8 | This network (source only) | No |
| 10.0.0.0/8 | /8 | Private (RFC 1918) | No |
| 100.64.0.0/10 | /10 | Carrier-grade NAT (RFC 6598) | No |
| 127.0.0.0/8 | /8 | Loopback | No |
| 169.254.0.0/16 | /16 | Link-local (APIPA) | No |
| 172.16.0.0/12 | /12 | Private (RFC 1918) | No |
| 192.0.2.0/24 | /24 | Documentation (TEST-NET-1) | No |
| 192.88.99.0/24 | /24 | IPv6 to IPv4 relay (deprecated) | Special |
| 192.168.0.0/16 | /16 | Private (RFC 1918) | No |
| 198.18.0.0/15 | /15 | Benchmark testing | No |
| 198.51.100.0/24 | /24 | Documentation (TEST-NET-2) | No |
| 203.0.113.0/24 | /24 | Documentation (TEST-NET-3) | No |
| 224.0.0.0/4 | /4 | Multicast | Special |
| 240.0.0.0/4 | /4 | Reserved (formerly 'Class E') | No |
| 255.255.255.255/32 | /32 | Limited broadcast | No |
| Class | Range | CIDR | Addresses | Common Use |
|---|---|---|---|---|
| Class A | 10.0.0.0 - 10.255.255.255 | /8 | 16.7M | Large enterprises, cloud providers |
| Class B | 172.16.0.0 - 172.31.255.255 | /12 | 1.04M | Medium enterprises, VPNs |
| Class C | 192.168.0.0 - 192.168.255.255 | /16 | 65K | Small offices, home networks |
Interview gotcha: 172.16.0.0/12 goes up to 172.31.255.255, NOT 172.255.255.255. Many candidates incorrectly think it's /8.
Let's work through the most common types of subnetting questions you'll encounter in interviews.
IP: 172.25.217.50
Mask: /21Step 1: /21 = 255.255.248.0 (third octet is interesting)
Block size = 256 - 248 = 8
Step 2: 217 / 8 = 27.125 → Subnet index = 27
Third octet starts at: 27 × 8 = 216
Step 3: Network = 172.25.216.0/21
Broadcast = 172.25.223.255
Range: 172.25.216.0 - 172.25.223.255The host 172.25.217.50 belongs to the 172.25.216.0/21 subnet. This subnet spans 3rd octet values 216-223 and the full 4th octet.
Network: 172.30.0.0/16 (65,534 hosts)
Required: 60 subnets × 500+ hosts eachStep 1: How many subnet bits for 60 subnets?
2^6 = 64 ≥ 60 ✓ → Need 6 subnet bits
Step 2: Calculate host bits remaining
Original host bits: 16
Subnet bits needed: 6
Remaining host bits: 16 - 6 = 10
Hosts per subnet: 2^10 - 2 = 1022 ≥ 500 ✓
Step 3: New mask
/16 + 6 = /22
**Answer: Yes. Use /22 subnets.**
Each /22 provides 1022 hosts.
60 subnets × 1022 hosts = 61,320 hosts allocated.Always check both requirements: enough subnets AND enough hosts per subnet. With /22, we get 64 subnets of 1022 hosts each—meeting both requirements.
Allocated: 10.50.0.0/22 (1022 usable addresses)
Main: 400, Library: 80, Dorm: 200, Mgmt: 20
Total needed: 700 hostsStep 1: Sort by size: 400, 200, 80, 20
Step 2: Find required mask for each:
• 400 hosts → 2^9 = 512 ≥ 402 → /23 (510 usable)
• 200 hosts → 2^8 = 256 ≥ 202 → /24 (254 usable)
• 80 hosts → 2^7 = 128 ≥ 82 → /25 (126 usable)
• 20 hosts → 2^5 = 32 ≥ 22 → /27 (30 usable)
Step 3: Allocate (largest first):
• Main: 10.50.0.0/23 (10.50.0.1 - 10.50.1.254)
• Dorm: 10.50.2.0/24 (10.50.2.1 - 10.50.2.254)
• Library: 10.50.3.0/25 (10.50.3.1 - 10.50.3.126)
• Mgmt: 10.50.3.128/27 (10.50.3.129 - 10.50.3.158)
Remaining: 10.50.3.160/27 through 10.50.3.224/27 (future use)This design fits all requirements in the /22 with room to spare. The largest allocation (Main) gets a contiguous /23, and smaller allocations fit in the remaining space without overlap.
Under time pressure, these techniques will help you solve subnetting problems quickly.
Create this reference: CIDR | Mask | Block | Hosts: /25|128|128|126, /26|192|64|62, /27|224|32|30, /28|240|16|14, /29|248|8|6, /30|252|4|2. With this memorized, you can solve most problems without calculation.
Subnetting is a fundamental skill that becomes automatic with practice. Here are the essential takeaways:
You now have comprehensive subnetting skills. The next page covers protocol analysis problems—how to compare protocols, analyze packet structures, and make design decisions based on protocol trade-offs.