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
| Prefix | Subnet mask | Wildcard | Block size | Addresses | Usable hosts |
|---|---|---|---|---|---|
| /24 | 255.255.255.0 | 0.0.0.255 | 256 | 256 | 254 |
| /25 | 255.255.255.128 | 0.0.0.127 | 128 | 128 | 126 |
| /26 | 255.255.255.192 | 0.0.0.63 | 64 | 64 | 62 |
| /27 | 255.255.255.224 | 0.0.0.31 | 32 | 32 | 30 |
| /28 | 255.255.255.240 | 0.0.0.15 | 16 | 16 | 14 |
| /29 | 255.255.255.248 | 0.0.0.7 | 8 | 8 | 6 |
| /30 | 255.255.255.252 | 0.0.0.3 | 4 | 4 | 2 |
| /31 | 255.255.255.254 | 0.0.0.1 | 2 | 2 | 2 (point-to-point, RFC 3021) |
| /32 | 255.255.255.255 | 0.0.0.0 | 1 | 1 | 1 (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
| Prefix | Subnet mask | Wildcard | Block size | Addresses | Usable hosts |
|---|---|---|---|---|---|
| /16 | 255.255.0.0 | 0.0.255.255 | 256 | 65,536 | 65,534 |
| /17 | 255.255.128.0 | 0.0.127.255 | 128 | 32,768 | 32,766 |
| /18 | 255.255.192.0 | 0.0.63.255 | 64 | 16,384 | 16,382 |
| /19 | 255.255.224.0 | 0.0.31.255 | 32 | 8,192 | 8,190 |
| /20 | 255.255.240.0 | 0.0.15.255 | 16 | 4,096 | 4,094 |
| /21 | 255.255.248.0 | 0.0.7.255 | 8 | 2,048 | 2,046 |
| /22 | 255.255.252.0 | 0.0.3.255 | 4 | 1,024 | 1,022 |
| /23 | 255.255.254.0 | 0.0.1.255 | 2 | 512 | 510 |
The one row to memorize
Every mask octet is one of these values. The block size is 256 minus the mask value.
| 1 bits in the octet | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Mask value | 128 | 192 | 224 | 240 | 248 | 252 | 254 | 255 |
| Block size | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
The magic number method
- Find the interesting octet: the octet where the mask is neither 255 nor 0.
- Magic number (block size) = 256 − the mask value in that octet.
- 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.
- 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).
- First host = network + 1. Last host = broadcast − 1.
- 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.
- Magic number: 256 − 254 = 2, counted in the third octet.
- Network: the largest multiple of 2 that is less than or equal to 222 is 222, so the network is 10.226.222.0.
- Next network: 222 + 2 = 224, so 10.226.224.0. The broadcast is one address less: 10.226.223.255.
- First usable host: 10.226.222.1. Last usable host: 10.226.223.254.
- 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
- /27 gives a mask of 255.255.255.224. The interesting octet is the fourth (224); magic number 256 − 224 = 32.
- Multiples of 32: 0, 32, 64, 96 … 64 ≤ 77 < 96, so the network is 172.16.45.64.
- Next network: 172.16.45.96, so the broadcast is 172.16.45.95.
- First usable host: 172.16.45.65. Last usable host: 172.16.45.94.
- Usable hosts: 25 − 2 = 30.
Worked example 3: 172.20.99.10/20
- /20 gives a mask of 255.255.240.0. The interesting octet is the third (240); magic number 256 − 240 = 16.
- Multiples of 16: … 80, 96, 112. 96 ≤ 99 < 112, so the network is 172.20.96.0.
- Next network: 172.20.112.0, so the broadcast is 172.20.111.255.
- First usable host: 172.20.96.1. Last usable host: 172.20.111.254.
- 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.
| Subnet mask | Wildcard mask | Matches |
|---|---|---|
| 255.255.255.255 | 0.0.0.0 | One host (IOS keyword host) |
| 255.255.255.252 | 0.0.0.3 | A /30 (4 addresses) |
| 255.255.255.192 | 0.0.0.63 | A /26 (64 addresses) |
| 255.255.255.0 | 0.0.0.255 | A /24 (256 addresses) |
| 255.255.0.0 | 0.0.255.255 | A /16 |
| 0.0.0.0 | 255.255.255.255 | Any 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 0Use 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.
| Segment | Hosts needed | Prefix (usable) | Subnet | Usable range | Broadcast |
|---|---|---|---|---|---|
| LAN A | 100 | /25 (126) | 192.168.10.0/25 | 192.168.10.1 – 192.168.10.126 | 192.168.10.127 |
| LAN B | 50 | /26 (62) | 192.168.10.128/26 | 192.168.10.129 – 192.168.10.190 | 192.168.10.191 |
| LAN C | 20 | /27 (30) | 192.168.10.192/27 | 192.168.10.193 – 192.168.10.222 | 192.168.10.223 |
| WAN 1 | 2 | /30 (2) | 192.168.10.224/30 | 192.168.10.225 – 192.168.10.226 | 192.168.10.227 |
| WAN 2 | 2 | /30 (2) | 192.168.10.228/30 | 192.168.10.229 – 192.168.10.230 | 192.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
| Range | Purpose |
|---|---|
| 10.0.0.0/8 | Private (RFC 1918) |
| 172.16.0.0/12 (172.16.0.0 – 172.31.255.255) | Private (RFC 1918) |
| 192.168.0.0/16 | Private (RFC 1918) |
| 127.0.0.0/8 | Loopback |
| 169.254.0.0/16 | Link-local (APIPA), self-assigned when DHCP fails |
| 224.0.0.0/4 (224 – 239 in the first octet) | Multicast (former class D) |
| Class | First octet | Default mask |
|---|---|---|
| A | 1 – 126 (0 and 127 are reserved) | 255.0.0.0 (/8) |
| B | 128 – 191 | 255.255.0.0 (/16) |
| C | 192 – 223 | 255.255.255.0 (/24) |
| D | 224 – 239 | Multicast, no mask |
| E | 240 – 255 | Reserved |
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.