Subnetting
Subnetting divides a large network into smaller sub-networks (subnets). It improves security, reduces broadcast traffic, and makes efficient use of IP addresses.
Key Formulas
2ⁿ
Number of Subnets
n = borrowed bits
2ʰ - 2
Usable Hosts/Subnet
h = remaining host bits
256 - mask
Block Size
mask = last non-255 octet
Step-by-Step Subnetting Process
Determine the IP class
Identify if the IP is Class A, B, or C to know the default subnet mask.
Determine subnets needed
Calculate how many subnets are required. Use formula: 2^n ≥ subnets needed (n = borrowed bits).
Borrow bits from host portion
Borrow bits from the host part to create subnet bits. Each borrowed bit doubles the number of subnets.
Calculate new subnet mask
Add borrowed bits to the default mask. E.g., /24 + 2 bits = /26 (255.255.255.192).
Calculate hosts per subnet
Hosts = 2^(remaining host bits) - 2 (subtract network and broadcast addresses).
List subnet ranges
Block size = 256 - last octet of mask. Subnets start at multiples of block size.
Worked Example
Given: 192.168.10.0/24 — 4 subnets needed
• Borrow 2 bits → 2² = 4 subnets ✓
• New prefix: /26 | New mask: 255.255.255.192
• Block size: 256 - 192 = 64
• Hosts per subnet: 2⁶ - 2 = 62 usable hosts
| Subnet | Network Address | First Host | Last Host | Broadcast |
|---|---|---|---|---|
| Subnet 1 | 192.168.10.0 | 192.168.10.1 | 192.168.10.62 | 192.168.10.63 |
| Subnet 2 | 192.168.10.64 | 192.168.10.65 | 192.168.10.126 | 192.168.10.127 |
| Subnet 3 | 192.168.10.128 | 192.168.10.129 | 192.168.10.190 | 192.168.10.191 |
| Subnet 4 | 192.168.10.192 | 192.168.10.193 | 192.168.10.254 | 192.168.10.255 |
CIDR Quick Reference
| CIDR | Subnet Mask | Hosts | Block Size |
|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,214 | — |
| /16 | 255.255.0.0 | 65,534 | — |
| /24 | 255.255.255.0 | 254 | 256 |
| /25 | 255.255.255.128 | 126 | 128 |
| /26 | 255.255.255.192 | 62 | 64 |
| /27 | 255.255.255.224 | 30 | 32 |
| /28 | 255.255.255.240 | 14 | 16 |
| /29 | 255.255.255.248 | 6 | 8 |
| /30 | 255.255.255.252 | 2 | 4 |
Interview Questions
Q: Why do we subtract 2 from usable hosts?
One address is the network address (all host bits = 0) and one is the broadcast address (all host bits = 1). Neither can be assigned to a host.
Q: What is VLSM?
Variable Length Subnet Masking — allows different subnets to have different sizes, making more efficient use of IP address space.
Q: What is CIDR?
Classless Inter-Domain Routing — uses prefix notation (/n) instead of class-based masks, allowing flexible allocation of IP addresses.
Q: How many subnets does /26 create from a /24?
4 subnets (2 borrowed bits = 2² = 4), each with 62 usable hosts.