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
In a nutshell
  • 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.

IP address192.168.10.25AND withSubnet mask255.255.255.0givesNetwork ID192.168.10.0

How it works

Address types

TypeRangeNotes
Private (Request for Comments, RFC, 1918)10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16Not routed on the internet, used with Network Address Translation (NAT)
Loopback127.0.0.0/8127.0.0.1 refers to the local host
Automatic Private IP Addressing (APIPA), link local169.254.0.0/16Self assigned when no Dynamic Host Configuration Protocol (DHCP) answer arrives
Shared address space100.64.0.0/10Used by providers for carrier grade NAT
Multicast224.0.0.0 to 239.255.255.255Group delivery
PublicEverything else usableGlobally 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

ClassFirst octetDefault mask
A1 to 126255.0.0.0 (/8)
B128 to 191255.255.0.0 (/16)
C192 to 223255.255.255.0 (/24)
D224 to 239Multicast
E240 to 255Reserved

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.

PrefixMaskBlock sizeUsable hosts
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/30255.255.255.25242

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.

192.168.10.0/24one networksplit into four/26 subnetsblock size 64such as192.168.10.64hosts .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.
Exam tip

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.

Watch out

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.