🎯 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 7Bit 6Bit 5Bit 4Bit 3Bit 2Bit 1Bit 0Decimal
1286432168421
11000000192
11111111255
000000000
10101000168
# 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

ClassFirst OctetDefault MaskPrivate RangeHosts
A1–126/8 (255.0.0.0)10.0.0.0/816,777,214
B128–191/16 (255.255.0.0)172.16.0.0/1265,534
C192–223/24 (255.255.255.0)192.168.0.0/16254
D224–239β€”Multicastβ€”
E240–255β€”Experimentalβ€”
πŸ’‘
Loopback: 127.0.0.0/8 is reserved for loopback (127.0.0.1). APIPA: 169.254.0.0/16 is link-local (auto-assigned when DHCP fails).

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

CIDRSubnet MaskHostsSubnets of /24
/24255.255.255.02541
/25255.255.255.1281262
/26255.255.255.192624
/27255.255.255.224308
/28255.255.255.2401416
/29255.255.255.248632
/30255.255.255.252264
/32255.255.255.2551 (host route)256

Step 1 β€” Subnet Mask Basics

1

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

2

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

3

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

4

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.

1

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

2

You have 10.0.0.0/8. How many /19 subnets can you create?

Hint: Subnets = 2(new prefix βˆ’ old prefix)

3

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

/PrefixMaskWildcardHostsBlock
/24255.255.255.00.0.0.255254256
/25255.255.255.1280.0.0.127126128
/26255.255.255.1920.0.0.636264
/27255.255.255.2240.0.0.313032
/28255.255.255.2400.0.0.151416
/29255.255.255.2480.0.0.768
/30255.255.255.2520.0.0.324
/32255.255.255.2550.0.0.011
βœ…
Lab Complete! Subnetting is the most tested CCNA topic. Practice until you can answer any question in under 90 seconds. Next: OSPF routing configuration.
Next: OSPF Lab β†’ ← All Labs