π― Lab Objectives
- Convert between decimal, binary, and CIDR notation
- Calculate network address, broadcast, and usable host range
- Divide a network into subnets of a required size
- Apply VLSM to allocate addresses efficiently
- Convert subnet masks to wildcard masks for ACLs and OSPF
- Solve subnetting problems under exam-time pressure
Binary Refresher
IPv4 addresses are 32-bit numbers split into four 8-bit octets. Each bit position has a value: 128, 64, 32, 16, 8, 4, 2, 1.
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 | Decimal |
|---|---|---|---|---|---|---|---|---|
| 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 | |
| 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 192 |
| 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 255 |
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 168 |
# Quick binary conversions to memorise:
/8 = 255.0.0.0
/16 = 255.255.0.0
/24 = 255.255.255.0
/25 = 255.255.255.128
/26 = 255.255.255.192
/27 = 255.255.255.224
/28 = 255.255.255.240
/29 = 255.255.255.248
/30 = 255.255.255.252
IP Address Classes
| Class | First Octet | Default Mask | Private Range | Hosts |
|---|---|---|---|---|
| A | 1β126 | /8 (255.0.0.0) | 10.0.0.0/8 | 16,777,214 |
| B | 128β191 | /16 (255.255.0.0) | 172.16.0.0/12 | 65,534 |
| C | 192β223 | /24 (255.255.255.0) | 192.168.0.0/16 | 254 |
| D | 224β239 | β | Multicast | β |
| E | 240β255 | β | Experimental | β |
CIDR Notation
CIDR (Classless Inter-Domain Routing) replaces class-based addressing. The prefix length (/n) tells you how many bits are in the network portion.
Formula: Usable hosts = 2(32βprefix) β 2
| CIDR | Subnet Mask | Hosts | Subnets of /24 |
|---|---|---|---|
| /24 | 255.255.255.0 | 254 | 1 |
| /25 | 255.255.255.128 | 126 | 2 |
| /26 | 255.255.255.192 | 62 | 4 |
| /27 | 255.255.255.224 | 30 | 8 |
| /28 | 255.255.255.240 | 14 | 16 |
| /29 | 255.255.255.248 | 6 | 32 |
| /30 | 255.255.255.252 | 2 | 64 |
| /32 | 255.255.255.255 | 1 (host route) | 256 |
Step 1 β Subnet Mask Basics
A subnet mask has all 1s in the network portion, all 0s in the host portion
For a /26: 11111111.11111111.11111111.11000000 = 255.255.255.192
The "magic number" (or "block size") is key to fast subnetting: 256 β last octet of mask
# /26 = mask 255.255.255.192
Magic number = 256 - 192 = 64
Subnets start at: 0, 64, 128, 192
# /27 = mask 255.255.255.224
Magic number = 256 - 224 = 32
Subnets start at: 0, 32, 64, 96, 128, 160, 192, 224
# /28 = mask 255.255.255.240
Magic number = 256 - 240 = 16
Subnets start at: 0, 16, 32, 48, 64, 80 ...
Step 2 β Finding the Network Address
Bitwise AND the IP address with the subnet mask
# Example: What network is 192.168.1.130/26 in?
Mask = /26 = 255.255.255.192, magic = 64
Block containing 130: 64 Γ 2 = 128 β€ 130 < 192
Network address = 192.168.1.128
# Example: 10.0.5.200/27
Mask = /27 = 255.255.255.224, magic = 32
Block containing 200: 32 Γ 6 = 192 β€ 200 < 224
Network address = 10.0.5.192
Step 3 β Finding the Broadcast Address
Broadcast = next network address β 1
# For 192.168.1.128/26:
Network = 192.168.1.128
Next net = 192.168.1.192 (128 + 64)
Broadcast = 192.168.1.191
# For 10.0.5.192/27:
Network = 10.0.5.192
Next net = 10.0.5.224 (192 + 32)
Broadcast = 10.0.5.223
Step 4 β Usable Host Range
First usable = Network + 1 Β· Last usable = Broadcast β 1
# Complete example: 172.16.50.0/28
Mask = 255.255.255.240 (magic = 16)
Network = 172.16.50.0
Broadcast = 172.16.50.15
First host = 172.16.50.1
Last host = 172.16.50.14
Hosts = 2^(32-28) - 2 = 14
Step 5 β Subnetting a Network
Scenario: You have 192.168.10.0/24 and need 5 subnets of at least 25 hosts each.
# Step 1: How many host bits needed for 25 hosts?
2^5 = 32 hosts (30 usable) β β borrow 3 bits from host portion
New prefix = /24 + 3 = /27
Mask = 255.255.255.224, magic = 32
# Step 2: List all /27 subnets of 192.168.10.0/24
192.168.10.0/27 β hosts .1 β .30 broadcast .31
192.168.10.32/27 β hosts .33 β .62 broadcast .63
192.168.10.64/27 β hosts .65 β .94 broadcast .95
192.168.10.96/27 β hosts .97 β .126 broadcast .127
192.168.10.128/27 β hosts .129 β .158 broadcast .159
192.168.10.160/27 β hosts .161 β .190 broadcast .191
192.168.10.192/27 β hosts .193 β .222 broadcast .223
192.168.10.224/27 β hosts .225 β .254 broadcast .255
# We have 8 subnets β more than the 5 required β
Step 6 β VLSM (Variable Length Subnet Masking)
VLSM lets you assign different-sized subnets from one block to avoid wasting IP addresses.
Scenario: Starting with 10.1.1.0/24, allocate for: Site A (100 hosts), Site B (50 hosts), Site C (25 hosts), WAN link (2 hosts).
# Rule: Always allocate largest subnet first!
Site A (100 hosts): need /25 (126 hosts)
β 10.1.1.0/25 (.1 β .126, broadcast .127)
Site B (50 hosts): need /26 (62 hosts)
β 10.1.1.128/26 (.129 β .190, broadcast .191)
Site C (25 hosts): need /27 (30 hosts)
β 10.1.1.192/27 (.193 β .222, broadcast .223)
WAN link (2 hosts): need /30 (2 hosts)
β 10.1.1.224/30 (.225 β .226, broadcast .227)
# Remaining space: 10.1.1.228 β 10.1.1.255 (available for future)
Step 7 β Wildcard Masks
Wildcard masks are the inverse of subnet masks. Used in ACLs and OSPF network statements. Wildcard = 255.255.255.255 β subnet mask
# Subnet mask β Wildcard mask
255.255.255.0 β 0.0.0.255 (/24)
255.255.255.128 β 0.0.0.127 (/25)
255.255.255.192 β 0.0.0.63 (/26)
255.255.255.224 β 0.0.0.31 (/27)
255.255.255.240 β 0.0.0.15 (/28)
255.255.255.252 β 0.0.0.3 (/30)
# Cisco ACL examples:
permit ip 192.168.1.0 0.0.0.255 any ! permit all of /24
permit ip 10.0.0.0 0.255.255.255 any ! permit all of /8
permit host 192.168.1.1 ! single host (0.0.0.0 wildcard)
# OSPF network statement:
network 192.168.1.0 0.0.0.255 area 0
Step 8 β ipcalc Tool
# Install
sudo apt install ipcalc
# Calculate subnet info
ipcalc 192.168.1.130/26
# Output:
Address: 192.168.1.130 11000000.10101000.00000001.10 000010
Netmask: 255.255.255.192 = 26 11111111.11111111.11111111.11 000000
Network: 192.168.1.128/26
HostMin: 192.168.1.129
HostMax: 192.168.1.190
Broadcast: 192.168.1.191
Hosts/Net: 62
Practice Problems
Work through these before looking at the answers. Time yourself β CCNA exam allows ~90 seconds per subnetting question.
What network does 172.16.45.200/20 belong to?
Hint: /20 = 255.255.240.0 β the interesting octet is the third. Magic = 256β240 = 16
You have 10.0.0.0/8. How many /19 subnets can you create?
Hint: Subnets = 2(new prefix β old prefix)
What is the wildcard mask for 255.255.255.248?
Show Answers
1. /20 = 255.255.240.0, magic=16. Third octet: 45Γ·16=2 remainder 13, so block is 32β47. Network = 172.16.32.0/20, Broadcast = 172.16.47.255
2. 2(19β8) = 211 = 2048 subnets
3. 255.255.255.255 β 255.255.255.248 = 0.0.0.7
π Subnetting Quick Reference
| /Prefix | Mask | Wildcard | Hosts | Block |
|---|---|---|---|---|
| /24 | 255.255.255.0 | 0.0.0.255 | 254 | 256 |
| /25 | 255.255.255.128 | 0.0.0.127 | 126 | 128 |
| /26 | 255.255.255.192 | 0.0.0.63 | 62 | 64 |
| /27 | 255.255.255.224 | 0.0.0.31 | 30 | 32 |
| /28 | 255.255.255.240 | 0.0.0.15 | 14 | 16 |
| /29 | 255.255.255.248 | 0.0.0.7 | 6 | 8 |
| /30 | 255.255.255.252 | 0.0.0.3 | 2 | 4 |
| /32 | 255.255.255.255 | 0.0.0.0 | 1 | 1 |