Networking Concepts · Topic 9 of 11
IPv4 Addressing and Subnetting
Learn IPv4 address classes, private and special ranges, subnet masks, CIDR notation, VLSM and how to work out hosts, networks and broadcast addresses.
- 5 min
- Private ranges: 10.0.0.0/8, 172.16.0.0/12 (172.16 to 172.31) and 192.168.0.0/16.
- 127.0.0.0/8 is loopback. 169.254.0.0/16 is APIPA.
- Usable hosts equal 2 to the power of the host bits, minus 2.
What it is
An Internet Protocol version 4 (IPv4) address is 32 bits long, written as four decimal numbers called octets, such as 192.168.10.25. A subnet mask splits the address into a network part and a host part.
The exam asks you to identify address types, read the mask in Classless Inter-Domain Routing (CIDR) notation, and work out how many hosts and subnets a design gives.
How it works
Address types
| Type | Range | Notes |
|---|---|---|
| Private (Request for Comments, RFC, 1918) | 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 | Not routed on the internet, used with Network Address Translation (NAT) |
| Loopback | 127.0.0.0/8 | 127.0.0.1 refers to the local host |
| Automatic Private IP Addressing (APIPA), link local | 169.254.0.0/16 | Self assigned when no Dynamic Host Configuration Protocol (DHCP) answer arrives |
| Shared address space | 100.64.0.0/10 | Used by providers for carrier grade NAT |
| Multicast | 224.0.0.0 to 239.255.255.255 | Group delivery |
| Public | Everything else usable | Globally routable |
APIPA assigns a 169.254.x.x address when a DHCP server cannot be reached. Seeing one on a client usually means the DHCP service failed.
Classes
| Class | First octet | Default mask |
|---|---|---|
| A | 1 to 126 | 255.0.0.0 (/8) |
| B | 128 to 191 | 255.255.0.0 (/16) |
| C | 192 to 223 | 255.255.255.0 (/24) |
| D | 224 to 239 | Multicast |
| E | 240 to 255 | Reserved |
Classful addressing is largely replaced by CIDR, which allows any prefix length. The class names still appear in exam questions.
Subnet masks and CIDR
The prefix length is the count of 1 bits in the mask. A /24 is 255.255.255.0, a /26 is 255.255.255.192, and a /30 is 255.255.255.252.
The number of usable hosts is 2 to the power of the host bits, minus 2. The two removed addresses are the network address and the broadcast address.
| Prefix | Mask | Block size | Usable hosts |
|---|---|---|---|
| /24 | 255.255.255.0 | 256 | 254 |
| /25 | 255.255.255.128 | 128 | 126 |
| /26 | 255.255.255.192 | 64 | 62 |
| /27 | 255.255.255.224 | 32 | 30 |
| /28 | 255.255.255.240 | 16 | 14 |
| /30 | 255.255.255.252 | 4 | 2 |
Worked example
Take 192.168.10.100/26. The block size is 64, so the subnets start at .0, .64, .128 and .192.
The address .100 falls in the .64 subnet. The network address is 192.168.10.64, the broadcast address is 192.168.10.127, and usable hosts are .65 to .126.
Variable length subnet masking
Variable length subnet masking (VLSM) uses different prefix lengths inside one address space. A point to point link needs only two addresses, so a /30 saves space, while a large user virtual local area network (VLAN) may need a /24.
Allocate the largest subnets first, then fit the smaller ones into the remaining space without overlapping.
Default gateway and special cases
A host sends traffic for another subnet to its default gateway, which is the local router address. If the gateway is wrong or in another subnet, remote access fails while local access still works.
A /31 can be used on point to point links, and a /32 identifies a single host, such as a loopback on a router.
What to remember for the exam
- Private ranges: 10.0.0.0/8, 172.16.0.0/12 (172.16 to 172.31) and 192.168.0.0/16.
- 127.0.0.0/8 is loopback. 169.254.0.0/16 is APIPA.
- Usable hosts equal 2 to the power of the host bits, minus 2.
- A /24 gives 254 hosts, a /26 gives 62, a /27 gives 30, a /28 gives 14, and a /30 gives 2.
- The network address has all host bits 0. The broadcast address has all host bits 1.
- Class A starts at 1 to 126, class B at 128 to 191, and class C at 192 to 223.
- VLSM uses different prefix lengths to avoid wasting addresses.
- A host cannot reach other subnets without a correct default gateway in its own subnet.
Find the block size by subtracting the interesting octet of the mask from 256. For 255.255.255.192 the block size is 64, so subnets start at 0, 64, 128 and 192.
Common mistakes
Forgetting to subtract 2. The network and broadcast addresses cannot be assigned to hosts.
Treating all 172 addresses as private. Only 172.16.0.0 through 172.31.255.255 are private.
Reading APIPA as a working address. A 169.254 address means the host did not receive a lease, and it can only talk to the local link.
Mixing up the prefix and the mask. /27 means 27 bits of network, which is the mask 255.255.255.224.
Placing the gateway outside the subnet. The default gateway must be an address inside the host's own subnet.
Do not treat 127.0.0.1 as an address on the local area network (LAN). A ping to the loopback address tests the local network stack only, not the cable or the network.
Check yourself
Work through these three.
How many usable hosts are in a /27?
30 hosts, since 32 addresses minus the network and broadcast addresses leaves 30.
A client shows the address 169.254.12.7. What does it mean?
The client got no answer from a DHCP server and assigned itself an APIPA address.
What is the broadcast address of 192.168.10.64/26?
192.168.10.127.
Topic 9 of 11 in Networking Concepts
Test yourself on Networking Concepts
The full CompTIA Network+ N10-009 question bank has 910 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by CompTIA. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.