Linkwing

IPv4 subnetting cheat sheet for the CCNA

By Ata Tunc Bilge · Published

Everything you need to subnet IPv4 addresses for the CCNA 200-301 exam, on one page: mask tables from /16 to /32, the magic number method with three worked examples, wildcard masks, a VLSM example and the reference ranges worth memorizing. Every number on this page was checked with a script.

The formulas

  • An IPv4 address has 32 bits. The prefix length /n is the number of network bits; the remaining h = 32 − n bits are host bits.
  • Usable hosts per subnet = 2h − 2, because the first address is the network address and the last is the broadcast address. The exceptions are /31 and /32 (see the table).
  • Subnets created by borrowing s bits = 2s. For example, splitting a /24 into /27s borrows 3 bits and gives 8 subnets.
  • Block size, or magic number = 256 − the mask value in the interesting octet.

Mask table: /24 to /32

Prefixes in the fourth octet
PrefixSubnet maskWildcardBlock sizeAddressesUsable hosts
/24255.255.255.00.0.0.255256256254
/25255.255.255.1280.0.0.127128128126
/26255.255.255.1920.0.0.63646462
/27255.255.255.2240.0.0.31323230
/28255.255.255.2400.0.0.15161614
/29255.255.255.2480.0.0.7886
/30255.255.255.2520.0.0.3442
/31255.255.255.2540.0.0.1222 (point-to-point, RFC 3021)
/32255.255.255.2550.0.0.0111 (host route)
  • /31: no network or broadcast address. Both addresses are usable on point-to-point links, as defined in RFC 3021, which saves addresses on router-to-router links.
  • /32: a single address. Used for host routes and for loopback interfaces.

Mask table: /16 to /23

Prefixes in the third octet (block size counts in the third octet)
PrefixSubnet maskWildcardBlock sizeAddressesUsable hosts
/16255.255.0.00.0.255.25525665,53665,534
/17255.255.128.00.0.127.25512832,76832,766
/18255.255.192.00.0.63.2556416,38416,382
/19255.255.224.00.0.31.255328,1928,190
/20255.255.240.00.0.15.255164,0964,094
/21255.255.248.00.0.7.25582,0482,046
/22255.255.252.00.0.3.25541,0241,022
/23255.255.254.00.0.1.2552512510

The one row to memorize

Every mask octet is one of these values. The block size is 256 minus the mask value.

Mask octet values by number of 1 bits
1 bits in the octet12345678
Mask value128192224240248252254255
Block size1286432168421

The magic number method

  1. Find the interesting octet: the octet where the mask is neither 255 nor 0.
  2. Magic number (block size) = 256 − the mask value in that octet.
  3. Network address: in the interesting octet, take the largest multiple of the magic number that is less than or equal to the address's value. Set every octet to the right to 0.
  4. Next network: network value + magic number in the interesting octet. The broadcast address is one less than the next network (octets to the right become 255).
  5. First host = network + 1. Last host = broadcast − 1.
  6. Usable hosts = 2h − 2.

Worked example 1: 10.226.222.134/23

/23 means 23 network bits and 9 host bits. The mask is 255.255.254.0, so the interesting octet is the third one, with a mask value of 254.

  1. Magic number: 256 − 254 = 2, counted in the third octet.
  2. Network: the largest multiple of 2 that is less than or equal to 222 is 222, so the network is 10.226.222.0.
  3. Next network: 222 + 2 = 224, so 10.226.224.0. The broadcast is one address less: 10.226.223.255.
  4. First usable host: 10.226.222.1. Last usable host: 10.226.223.254.
  5. Usable hosts: 29 − 2 = 510.

This subnet spans two values of the third octet (222 and 223), so addresses such as 10.226.222.255 and 10.226.223.0 are ordinary host addresses inside it.

Worked example 2: 172.16.45.77/27

  1. /27 gives a mask of 255.255.255.224. The interesting octet is the fourth (224); magic number 256 − 224 = 32.
  2. Multiples of 32: 0, 32, 64, 96 … 64 ≤ 77 < 96, so the network is 172.16.45.64.
  3. Next network: 172.16.45.96, so the broadcast is 172.16.45.95.
  4. First usable host: 172.16.45.65. Last usable host: 172.16.45.94.
  5. Usable hosts: 25 − 2 = 30.

Worked example 3: 172.20.99.10/20

  1. /20 gives a mask of 255.255.240.0. The interesting octet is the third (240); magic number 256 − 240 = 16.
  2. Multiples of 16: … 80, 96, 112. 96 ≤ 99 < 112, so the network is 172.20.96.0.
  3. Next network: 172.20.112.0, so the broadcast is 172.20.111.255.
  4. First usable host: 172.20.96.1. Last usable host: 172.20.111.254.
  5. Usable hosts: 212 − 2 = 4,094.

Wildcard masks

A wildcard mask is the inverse of a subnet mask: subtract each octet of the mask from 255. In a wildcard, a 0 bit means the address bit must match and a 1 bit means it is ignored. Cisco IOS uses wildcard masks in ACLs and in OSPF network statements.

Common wildcard masks
Subnet maskWildcard maskMatches
255.255.255.2550.0.0.0One host (IOS keyword host)
255.255.255.2520.0.0.3A /30 (4 addresses)
255.255.255.1920.0.0.63A /26 (64 addresses)
255.255.255.00.0.0.255A /24 (256 addresses)
255.255.0.00.0.255.255A /16
0.0.0.0255.255.255.255Any address (IOS keyword any)
! Match 192.168.10.64 to 192.168.10.127 (192.168.10.64/26)
access-list 10 permit 192.168.10.64 0.0.0.63

! Enable OSPF area 0 on interfaces in 10.1.1.0/24
router ospf 1
 network 10.1.1.0 0.0.0.255 area 0

Use the network address of the range in the statement. With 0.0.0.63 the last six bits are ignored, so 192.168.10.64 through 192.168.10.127 match.

VLSM example

VLSM (variable length subnet masking) means using different prefix lengths inside one block, so that each subnet is only as large as it needs to be. Allocate the largest subnets first so that each one starts on a boundary of its own block size.

Task: split 192.168.10.0/24 for LAN A (100 hosts), LAN B (50 hosts), LAN C (20 hosts) and two point-to-point WAN links.

VLSM plan for 192.168.10.0/24
SegmentHosts neededPrefix (usable)SubnetUsable rangeBroadcast
LAN A100/25 (126)192.168.10.0/25192.168.10.1 – 192.168.10.126192.168.10.127
LAN B50/26 (62)192.168.10.128/26192.168.10.129 – 192.168.10.190192.168.10.191
LAN C20/27 (30)192.168.10.192/27192.168.10.193 – 192.168.10.222192.168.10.223
WAN 12/30 (2)192.168.10.224/30192.168.10.225 – 192.168.10.226192.168.10.227
WAN 22/30 (2)192.168.10.228/30192.168.10.229 – 192.168.10.230192.168.10.231

Still free for growth: 192.168.10.232/29 (.232 to .239) and 192.168.10.240/28 (.240 to .255). If both routers support it, a /31 on each WAN link (RFC 3021) uses 2 addresses instead of 4.

Reference ranges

IPv4 ranges worth memorizing
RangePurpose
10.0.0.0/8Private (RFC 1918)
172.16.0.0/12 (172.16.0.0 – 172.31.255.255)Private (RFC 1918)
192.168.0.0/16Private (RFC 1918)
127.0.0.0/8Loopback
169.254.0.0/16Link-local (APIPA), self-assigned when DHCP fails
224.0.0.0/4 (224 – 239 in the first octet)Multicast (former class D)
Classful ranges (first octet)
ClassFirst octetDefault mask
A1 – 126 (0 and 127 are reserved)255.0.0.0 (/8)
B128 – 191255.255.0.0 (/16)
C192 – 223255.255.255.0 (/24)
D224 – 239Multicast, no mask
E240 – 255Reserved

Common mistakes

  • Forgetting the − 2: a /26 has 64 addresses but 62 usable hosts.
  • Stepping by the mask value instead of the block size: the /27 mask octet is 224, but /27 subnets step by 32.
  • Looking in the wrong octet: from /17 to /23 the interesting octet is the third, so the fourth octet runs through 0 to 255 inside one subnet.
  • Treating a /31 like a /30: on point-to-point links a /31 has two usable addresses and no broadcast.
  • Writing an ACL or OSPF statement with a host address and a wildcard that does not match the range you meant.

Practice

Speed comes from repetition. Do a few problems at a time, several days a week, and check each answer with the method above. Linkwing's Subnetting Gym generates unlimited drills on iPhone and works offline. For where subnetting fits into a full schedule, see the CCNA study plan.

Practice on your iPhone with Linkwing

Lessons from zero, 75 IOS command labs, a Subnetting Gym and timed mock exams. Free to download · iPhone · iOS 26 or later.

Download on the App Store