Objective 1.6
Configure and verify IPv4 addressing and subnetting
Interactive
The subnet boundary
An IPv4 address is 32 bits. The prefix length says how many of them, from the left, are the network. Slide the boundary and watch every derived value change.
- Mask
- 255.255.255.192
- Wildcard
- 0.0.0.63
- Network
- 192.168.10.64
- Broadcast
- 192.168.10.127
- Usable hosts
- 62
- Block size
- 64 in octet 4
19/23 A /26: 6 host bits give 2^6 = 64 addresses per subnet; block size 64 in the last octet.
This is the most important skill in Domain 1 and one of the most tested skills on the whole exam. Subnetting questions appear directly (“what is the broadcast address of…”) and hide inside routing, ACL, NAT, and troubleshooting questions. Work through this section with a pen and paper, and then practice until you can do any problem in under a minute.
IPv4 addresses and the IPv4 header
An IPv4 address is a 32-bit number that identifies an interface on a network.
Because 32-bit numbers are hard for people to read, we write them in dotted
decimal: four 8-bit groups called octets, each shown as a decimal number
from 0 to 255 and separated by dots, for example 192.168.10.25. The address has
two parts: the network portion (the leftmost bits, which identify the subnet
the host lives on, like a street name) and the host portion (the remaining
bits, which identify the individual host, like a house number). Every host on the
same subnet shares the same network portion.
The subnet mask tells devices where the boundary is. It is also 32 bits: a run
of 1s (marking network bits) followed by a run of 0s (marking host bits). The mask
255.255.255.0 is 24 ones and 8 zeros, so the first three octets are the network
and the last octet is the host. CIDR notation (Classless Inter-Domain Routing)
writes the same thing as a prefix length: 192.168.10.25/24 means “24
network bits.” Mask and prefix length are two ways of writing the same fact.
The IPv4 packet header is normally 20 bytes and includes: version (4), header length, DSCP (used by QoS), total length, identification and fragment fields, TTL (Time To Live, decremented by each router; the packet is discarded when it reaches 0, which prevents loops), protocol (6 = TCP, 17 = UDP, 1 = ICMP, 89 = OSPF), header checksum, source address, and destination address.
Binary conversion
Subnetting is arithmetic in base 2, so you must be comfortable converting an octet between decimal and binary. Each of the eight bit positions has a value that doubles from right to left:
| Bit | 8th | 7th | 6th | 5th | 4th | 3rd | 2nd | 1st |
|---|---|---|---|---|---|---|---|---|
| Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Binary to decimal: add up the values of the positions that are 1. The octet
11000000 has 1s in the 128 and 64 positions, so it is 192. The octet 10101100
is 128 + 32 + 8 + 4 = 172. 11111111 is all eight values added together, 255.
Decimal to binary: work left to right, subtracting each value if it fits.
Convert 203: 203 is at least 128, so write 1 and subtract (75 left). 75 is at
least 64: 1 (11 left). 11 is less than 32: 0. Less than 16: 0. 11 is at least 8:
1 (3 left). Less than 4: 0. 3 is at least 2: 1 (1 left). 1 is at least 1: 1.
Result: 11001011. Check: 128 + 64 + 8 + 2 + 1 = 203.
Memorize the eight valid subnet mask octet values, which are the only numbers that can appear in a mask because the 1s must be contiguous from the left:
| Binary | Decimal | Number of 1s |
|---|---|---|
| 00000000 | 0 | 0 |
| 10000000 | 128 | 1 |
| 11000000 | 192 | 2 |
| 11100000 | 224 | 3 |
| 11110000 | 240 | 4 |
| 11111000 | 248 | 5 |
| 11111100 | 252 | 6 |
| 11111110 | 254 | 7 |
| 11111111 | 255 | 8 |
If you see a mask such as 255.255.255.160, it is invalid (160 = 10100000 has a
gap in the ones).
The CIDR prefix and mask table
The full table of prefix lengths from /8 to /32 follows. The block size (also called the increment or magic number) is 256 minus the value of the interesting octet of the mask, meaning the last octet that is not 0 or 255. Hosts per subnet is 2 to the power of the number of host bits, minus 2 (one for the network address and one for the broadcast address).
| Prefix | Subnet mask | Host bits | Usable hosts | Block size (in interesting octet) |
|---|---|---|---|---|
| /8 | 255.0.0.0 | 24 | 16,777,214 | 1 (octet 1) |
| /9 | 255.128.0.0 | 23 | 8,388,606 | 128 (octet 2) |
| /10 | 255.192.0.0 | 22 | 4,194,302 | 64 (octet 2) |
| /11 | 255.224.0.0 | 21 | 2,097,150 | 32 (octet 2) |
| /12 | 255.240.0.0 | 20 | 1,048,574 | 16 (octet 2) |
| /13 | 255.248.0.0 | 19 | 524,286 | 8 (octet 2) |
| /14 | 255.252.0.0 | 18 | 262,142 | 4 (octet 2) |
| /15 | 255.254.0.0 | 17 | 131,070 | 2 (octet 2) |
| /16 | 255.255.0.0 | 16 | 65,534 | 1 (octet 2) |
| /17 | 255.255.128.0 | 15 | 32,766 | 128 (octet 3) |
| /18 | 255.255.192.0 | 14 | 16,382 | 64 (octet 3) |
| /19 | 255.255.224.0 | 13 | 8,190 | 32 (octet 3) |
| /20 | 255.255.240.0 | 12 | 4,094 | 16 (octet 3) |
| /21 | 255.255.248.0 | 11 | 2,046 | 8 (octet 3) |
| /22 | 255.255.252.0 | 10 | 1,022 | 4 (octet 3) |
| /23 | 255.255.254.0 | 9 | 510 | 2 (octet 3) |
| /24 | 255.255.255.0 | 8 | 254 | 1 (octet 3) |
| /25 | 255.255.255.128 | 7 | 126 | 128 (octet 4) |
| /26 | 255.255.255.192 | 6 | 62 | 64 (octet 4) |
| /27 | 255.255.255.224 | 5 | 30 | 32 (octet 4) |
| /28 | 255.255.255.240 | 4 | 14 | 16 (octet 4) |
| /29 | 255.255.255.248 | 3 | 6 | 8 (octet 4) |
| /30 | 255.255.255.252 | 2 | 2 | 4 (octet 4) |
| /31 | 255.255.255.254 | 1 | 2 (point-to-point only, RFC 3021) | 2 (octet 4) |
| /32 | 255.255.255.255 | 0 | 1 (a single host route) | 1 (octet 4) |
Notice the pattern: each time the prefix grows by one, the number of hosts halves and the number of subnets doubles.
Classful addressing (historical, but still tested)
Before CIDR (1993), the first bits of an address determined its class, and the class fixed the mask:
| Class | First octet range | Leading bits | Default mask | Purpose |
|---|---|---|---|---|
| A | 1 to 126 | 0 | /8 (255.0.0.0) | Very large networks |
| B | 128 to 191 | 10 | /16 (255.255.0.0) | Medium networks |
| C | 192 to 223 | 110 | /24 (255.255.255.0) | Small networks |
| D | 224 to 239 | 1110 | n/a | Multicast |
| E | 240 to 255 | 1111 | n/a | Experimental, reserved |
The 127.0.0.0/8 block (first octet 127) is reserved for loopback; 127.0.0.1
always means “this computer.” The 0.0.0.0/8 block means “this network” and
0.0.0.0 is used as the source by a host that has no address yet (DHCP) and as
the “any network” default route.
Modern networks are classless: the mask, not the first octet, determines the network. But the exam still uses classful language. When a question says “subnet the Class C network 192.168.1.0,” it means a /24; “borrowed bits” means bits taken from the classful host portion to create subnets.
The magic-number (block size) method
The fastest way to solve any subnetting problem is to identify the block size in the interesting octet and count in multiples of it. The full procedure:
- Find the interesting octet: the octet of the mask that is neither 255 nor 0 (if the mask is /8, /16, or /24, the interesting octet is the one that would be next; the block size is then 1).
- Compute the block size: 256 minus the mask value in that octet. For 224 the block size is 32; for 192 it is 64; for 240 it is 16.
- Find the subnet: the network address’s interesting octet is the highest multiple of the block size that is less than or equal to the host address’s interesting octet. All octets to the right become 0.
- Find the broadcast: the next subnet minus 1. That is, add the block size to the network’s interesting octet, subtract 1, and set all octets to the right to 255.
- Find the usable range: network + 1 through broadcast - 1.
Worked example 1: 192.168.10.77/26. A /26 is 255.255.255.192. The interesting
octet is the fourth, and the block size is 256 - 192 = 64. Subnets in this /24
start at 0, 64, 128, 192. The host octet 77 falls between 64 and 128, so the
network is 192.168.10.64. Broadcast is 128 - 1 = 127: 192.168.10.127. Usable
hosts are 192.168.10.65 through 192.168.10.126, which is 62 addresses
(2 to the power of 6, minus 2).
Worked example 2: 172.16.45.200/20. A /20 is 255.255.240.0. The interesting
octet is the third, block size 256 - 240 = 16. Multiples of 16: 0, 16, 32, 48. The
third octet 45 falls between 32 and 48, so the network is 172.16.32.0. Broadcast
is the octet before 48, with the rest all ones: 172.16.47.255. Usable range
172.16.32.1 to 172.16.47.254, 4,094 hosts (12 host bits).
Worked example 3: 10.37.129.5/13. A /13 is 255.248.0.0. Interesting octet is
the second, block size 256 - 248 = 8. Multiples: 0, 8, 16, 24, 32, 40. The second
octet 37 falls between 32 and 40: network 10.32.0.0, broadcast 10.39.255.255,
usable 10.32.0.1 to 10.39.255.254.
Worked example 4: 192.168.1.130/25. Mask 255.255.255.128, block size 128.
Subnets 0 and 128. 130 is in the 128 subnet: network 192.168.1.128, broadcast
192.168.1.255, usable .129 to .254, 126 hosts.
Worked example 5: is 10.1.6.1/23 on the same subnet as 10.1.7.254/23? Mask
255.255.254.0, block size 2 in the third octet. Multiples: 0, 2, 4, 6, 8. Both 6
and 7 fall in the block starting at 6, so both hosts are in 10.1.6.0/23 whose
broadcast is 10.1.7.255. Yes, they are on the same subnet.
Designing subnets: how many subnets, how many hosts
The other direction is design: given a network and a requirement, choose a mask. Two formulas:
- Subnets created = 2 to the power of the number of borrowed bits (bits added to the original prefix).
- Usable hosts per subnet = 2 to the power of the number of remaining host bits, minus 2.
Worked example 6: subnet 192.168.1.0/24 into /26s. Going from /24 to /26 borrows 2 bits, so 2 to the power of 2 = 4 subnets. Each has 6 host bits, so 62 usable hosts. Block size 64:
| Subnet | Network | First usable | Last usable | Broadcast |
|---|---|---|---|---|
| 1 | 192.168.1.0/26 | 192.168.1.1 | 192.168.1.62 | 192.168.1.63 |
| 2 | 192.168.1.64/26 | 192.168.1.65 | 192.168.1.126 | 192.168.1.127 |
| 3 | 192.168.1.128/26 | 192.168.1.129 | 192.168.1.190 | 192.168.1.191 |
| 4 | 192.168.1.192/26 | 192.168.1.193 | 192.168.1.254 | 192.168.1.255 |
Worked example 7: you need at least 6 subnets from a /24, each with at least 25 hosts. 6 subnets need 3 borrowed bits (2 to the power of 3 = 8; 2 bits would give only 4). That leaves 5 host bits, which gives 30 hosts, enough for 25. The answer is /27 (255.255.255.224), giving 8 subnets of 30 hosts.
Worked example 8: a subnet must hold 500 hosts. 8 host bits give 254, too few; 9 host bits give 510. 32 - 9 = 23, so a /23 (255.255.254.0).
Worked example 9: how many /29 subnets fit in a /24? 29 - 24 = 5 borrowed bits, so 32 subnets, each with 6 usable hosts.
The first subnet (all borrowed bits zero) is subnet zero and the last (all
ones) is the all-ones subnet. Ancient rules forbade using them; Cisco IOS has
had ip subnet-zero enabled by default since IOS 12.0, and the CCNA assumes both
are usable unless a question says otherwise.
VLSM: Variable Length Subnet Masking
Using the same mask everywhere (fixed-length subnetting) wastes addresses: a point-to-point link between two routers needs only 2 addresses, but a /26 would give it 62. VLSM means using different prefix lengths for different subnets in the same address block, sized to fit. The procedure is to list the requirements from largest to smallest, assign the largest first, and give each subsequent subnet the next available block that is aligned to its own block size.
Worked example 10: allocate 192.168.5.0/24 for these needs:
| Department | Hosts needed | Host bits | Prefix | Usable |
|---|---|---|---|---|
| Sales | 100 | 7 | /25 | 126 |
| Engineering | 50 | 6 | /26 | 62 |
| Guest Wi-Fi | 20 | 5 | /27 | 30 |
| Link R1 to R2 | 2 | 2 | /30 | 2 |
| Link R2 to R3 | 2 | 2 | /30 | 2 |
Assign in order of size:
| Subnet | Network | Usable range | Broadcast |
|---|---|---|---|
| Sales | 192.168.5.0/25 | .1 to .126 | 192.168.5.127 |
| Engineering | 192.168.5.128/26 | .129 to .190 | 192.168.5.191 |
| Guest Wi-Fi | 192.168.5.192/27 | .193 to .222 | 192.168.5.223 |
| Link R1-R2 | 192.168.5.224/30 | .225 to .226 | 192.168.5.227 |
| Link R2-R3 | 192.168.5.228/30 | .229 to .230 | 192.168.5.231 |
Everything from 192.168.5.232 to .255 remains free for future growth. Had we
assigned the /30 links first at .0 and .4, the /25 for Sales could not start
until .128 (the next aligned /25 boundary), and the remaining space would be
scattered in small pieces rather than one contiguous free block. Largest first
avoids that fragmentation.
For router-to-router links, Cisco also supports a /31 (RFC 3021), which uses
both addresses and has no broadcast, saving two addresses per link. IOS accepts
ip address 10.0.0.0 255.255.255.254 on point-to-point interfaces.
Wildcard masks
Access control lists (Domain 5) and the OSPF network command (Domain 3) do not
use subnet masks; they use wildcard masks, which are the bitwise inverse. In a
wildcard mask, a 0 bit means “this bit must match” and a 1 bit means “I do
not care about this bit.” To convert, subtract each octet of the subnet mask
from 255:
| Subnet mask | Wildcard mask | Matches |
|---|---|---|
| 255.255.255.255 | 0.0.0.0 | Exactly one host (same as the host keyword) |
| 255.255.255.252 | 0.0.0.3 | A /30 |
| 255.255.255.0 | 0.0.0.255 | A /24 |
| 255.255.240.0 | 0.0.15.255 | A /20 |
| 255.255.0.0 | 0.0.255.255 | A /16 |
| 255.0.0.0 | 0.255.255.255 | An /8 |
| 0.0.0.0 | 255.255.255.255 | Everything (same as the any keyword) |
A quick shortcut: the wildcard’s interesting octet is the block size minus 1. A
/27 has block size 32, so its wildcard is 0.0.0.31. Wildcards do not have to
be contiguous (0.0.255.0 is legal and matches any third octet), but the exam
almost always uses the contiguous form.
Configuring and verifying IPv4 addresses on Cisco IOS
An address is applied per interface in interface configuration mode. Router
interfaces are shut down by default, so no shutdown is required.
R1(config)# interface gigabitethernet 0/0
R1(config-if)# description LAN - Sales
R1(config-if)# ip address 192.168.5.1 255.255.255.128
R1(config-if)# no shutdown
R1(config-if)# exit
R1(config)# interface gigabitethernet 0/1
R1(config-if)# description Link to R2
R1(config-if)# ip address 192.168.5.225 255.255.255.252
R1(config-if)# no shutdown
! A second address on the same interface (rarely needed)
R1(config-if)# ip address 10.99.0.1 255.255.255.0 secondary
IOS will reject an attempt to assign a network or broadcast address to an interface (“Bad mask”) and will reject an address that overlaps another interface’s subnet.
On a Layer 2 switch, the IP address goes on the management SVI and a default gateway is needed so you can reach it from other subnets:
SW1(config)# interface vlan 1
SW1(config-if)# ip address 192.168.5.10 255.255.255.128
SW1(config-if)# no shutdown
SW1(config-if)# exit
SW1(config)# ip default-gateway 192.168.5.1
Verification commands and what to look for:
R1# show ip interface brief
Interface IP-Address OK? Method Status Protocol
GigabitEthernet0/0 192.168.5.1 YES manual up up
GigabitEthernet0/1 192.168.5.225 YES manual up up
GigabitEthernet0/2 unassigned YES unset administratively down down
R1# show ip interface gigabitethernet 0/0
GigabitEthernet0/0 is up, line protocol is up
Internet address is 192.168.5.1/25
Broadcast address is 255.255.255.255
Address determined by setup command
MTU is 1500 bytes
...
R1# show running-config interface gigabitethernet 0/0
interface GigabitEthernet0/0
description LAN - Sales
ip address 192.168.5.1 255.255.255.128
R1# show ip route connected
192.168.5.0/24 is variably subnetted, 4 subnets, 3 masks
C 192.168.5.0/25 is directly connected, GigabitEthernet0/0
L 192.168.5.1/32 is directly connected, GigabitEthernet0/0
C 192.168.5.224/30 is directly connected, GigabitEthernet0/1
L 192.168.5.225/32 is directly connected, GigabitEthernet0/1
The show ip interface command shows the interface address together with its
prefix length (192.168.5.1/25). In show ip route, each
configured interface produces a C (connected) route for the subnet and an
L (local) /32 route for the interface’s own address. ping and traceroute
confirm reachability once addresses are in place.