Numerical Problems in Computer Networks
Subnetting Problems
Read aloud is unavailable in this browser.
The Art and Science of Address Space Division
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.
IP Addressing Fundamentals
Before solving subnetting problems, you need rock-solid fundamentals in IP address structure.
IPv4 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
The subnet mask divides the IP address into two parts:
- Network portion: Identifies the network/subnet (left bits)
- Host portion: Identifies the specific device (right bits)
| 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).
Powers of 2 and Quick Mental Math
Subnetting speed depends on instant recall of powers of 2 and quick binary-decimal conversion.
Essential Powers of 2
| 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) |
The 256 Rule
A powerful shortcut: Subnet boundaries occur at intervals of the block size, which is: $$Block\ Size = 256 - Subnet\ Mask\ Octet$$
For example:
- /26 mask = 255.255.255.192 → Block size = 256 - 192 = 64
- Subnet boundaries: 0, 64, 128, 192
This means:
- 192.168.1.0/26 → Valid range: .0 to .63 (broadcast .63)
- 192.168.1.64/26 → Valid range: .64 to .127 (broadcast .127)
- 192.168.1.128/26 → Valid range: .128 to .191 (broadcast .191)
- 192.168.1.192/26 → Valid range: .192 to .255 (broadcast .255)
/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.
Core Subnetting Calculations
Given an IP address and subnet mask, you should be able to instantly determine:
- Network Address: The first address in the subnet (host bits all zeros)
- Broadcast Address: The last address in the subnet (host bits all ones)
- First Usable Host: Network address + 1
- Last Usable Host: Broadcast address - 1
- Total Hosts: 2^(host bits) - 2
Example 1: Standard Subnet Calculation
Given 192.168.5.130/26, find all subnet properties.
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**Explanation
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.
Example 2: Crossing Octet Boundaries
Given 10.45.137.200/20, find the network and broadcast addresses.
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**Explanation
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).
Variable Length Subnet Masking (VLSM)
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.
The VLSM Process
- List requirements in descending order by size
- Allocate the largest subnet first from available space
- Continue with next largest from remaining space
- Use remaining space for smaller subnets
- Reserve address space for future growth
Example Organization
Given: 192.168.10.0/24 to allocate for:
- Department A: 100 hosts
- Department B: 50 hosts
- Department C: 25 hosts
- Server VLAN: 10 hosts
- Point-to-point links: 4 links × 2 hosts each
Example 3: VLSM Allocation
Allocate 192.168.10.0/24 for the requirements above.
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%)**Explanation
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).
Supernetting and Route Aggregation
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.
When Can Networks Be Aggregated?
Networks can be summarized into a single route if:
- They are contiguous in address space
- The count is a power of 2 (2, 4, 8, 16...)
- The first network address is divisible by the block size
Aggregation Formula
To aggregate N networks of size /X: $$Aggregate\ prefix = X - log_2(N)$$
For example: 4 × /24 networks → /24 - log₂(4) = /24 - 2 = /22
Example 4: Route Summarization
Summarize the following routes into a single advertisement:
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**Explanation
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.
Example 5: Finding Maximum Aggregation
What's the largest possible aggregate for these 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 routesExplanation
When 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 Essentials
IPv6 subnetting follows the same principles as IPv4 but with much larger address space and different conventions.
IPv6 Address Structure
| 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
- 16 bits for subnetting = 65,536 subnets
- Each subnet is a /64 with 2^64 host addresses
End-user typically gets: /56 or /48
IPv6 Subnetting Rules
- Interface IDs are always /64 for SLAAC to work
- Point-to-point links use /127 (RFC 6164), or /64 with manual configuration
- No broadcast addresses — IPv6 uses multicast (ff02::1 for all-nodes)
- Nibble boundaries preferred — Subnet at /48, /52, /56, /60, /64 for readability
Example: /48 Allocation
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.
Special and Reserved Address Ranges
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 |
Private Address Space Details
| 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.
KEEP LEARNING
There’s more to understand.
You’re reading the introduction. Create a free account to read the complete lesson, save notes and keep track of your progress.