Skip to content

Beginner · IPv4 addressing · topic 12 of 57 · 30 min

IPv4 address structure and special ranges

Explanation

An IPv4 address is 32 bits split into a network part, which says which network the device is on, and a host part, which says which device it is. The old classes A, B and C are history now, but you still need to know them. Some ranges are special: the private ranges 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16, loopback 127.0.0.0/8, APIPA 169.254.0.0/16 and multicast 224.0.0.0/4.

What an IPv4 address is

An IP address (Internet Protocol address) is the logical address of a device on a network. It is used by routers to send packets from one network to another. IPv4, version 4 of the protocol, uses 32-bit addresses written as four octets in dotted decimal, like 192.168.1.20. With 32 bits there are 2 to the power 32 combinations, about 4.3 billion addresses in total.

Every address has two parts. The network part says which network the device belongs to. The host part says which device it is on that network. A separate number, the subnet mask, tells you where the network part ends and the host part begins. You will learn masks in the next topic.

Think of it like this: An IPv4 address is like a postal address with a PIN code. The PIN code (say 411001 for part of Pune) is the network part: the postal system uses it to send the letter to the right area. The house number and street are the host part: the local postman uses them to find the exact door. Routers look only at the network part, just as sorting offices look only at the PIN code.

The old classes: A, B, C, D and E

In the early internet, the first octet decided the size of the network. This is called classful addressing. You no longer configure networks this way, but the CCNA exam still expects you to know the classes, and many people still say "a class C network" when they mean a /24.

ClassFirst octetLeading bitsDefault maskUsed for
A1 to 126 (0 and 127 reserved)0255.0.0.0 (/8)Very large networks
B128 to 19110255.255.0.0 (/16)Medium networks
C192 to 223110255.255.255.0 (/24)Small networks
D224 to 2391110noneMulticast
E240 to 2551111noneExperimental, reserved

Classful addressing wasted huge numbers of addresses. A company that needed 300 addresses was too big for a class C (254 hosts) and got a class B with 65,534 hosts. In 1993 the internet moved to CIDR (Classless Inter-Domain Routing): any prefix length can be used, and the mask is always given with the address. That is the system used today.

Private addresses (RFC 1918)

RFC 1918 sets aside three ranges for private use inside homes, offices and campuses. Anyone can use them, and they are never routed on the public internet. Your home Wi-Fi router almost certainly uses one of them.

RangeCoversTypical use
10.0.0.0/810.0.0.0 to 10.255.255.255Large companies, banks, cloud VPCs
172.16.0.0/12172.16.0.0 to 172.31.255.255Medium networks, Docker default networks
192.168.0.0/16192.168.0.0 to 192.168.255.255Homes and small offices
Careful: Common mistake: thinking all of 172.x.x.x is private. Only 172.16 to 172.31 is private. 172.32.0.1 and 172.15.0.1 are public addresses.

Why private addresses and NAT exist

4.3 billion addresses sounded huge in 1981, but today there are far more phones, laptops and servers than that. IANA, the body at the top of address allocation, handed out its last free IPv4 blocks in 2011, and the regional registries, including APNIC for India and the Asia-Pacific, ran short soon after. Two fixes keep IPv4 going: private addresses, which thousands of organisations reuse internally, and NAT (Network Address Translation), where a router swaps many private addresses for one or a few public addresses on the way out. The long-term fix is IPv6, covered in the next module.

Other special addresses

  • Loopback, 127.0.0.0/8: traffic to these addresses never leaves the device. 127.0.0.1 means "this computer". ping 127.0.0.1 tests your own network software.
  • APIPA (Automatic Private IP Addressing), 169.254.0.0/16: a Windows or Mac PC gives itself one of these when it cannot reach a DHCP server. Seeing 169.254.x.x on a PC almost always means "DHCP failed".
  • 0.0.0.0: means "this host, no address yet" when a PC asks DHCP for an address. In routing, 0.0.0.0/0 means "every network", the default route.
  • 255.255.255.255: the limited broadcast. A packet sent here goes to every device on the local network and is never forwarded by a router.
  • Documentation ranges 192.0.2.0/24, 198.51.100.0/24 and 203.0.113.0/24: reserved for books and examples, so this course uses them for "public" examples.

Unicast, broadcast and multicast

Unicast is one sender to one receiver, the normal case. Broadcast is one sender to every device on the local network, for example a DHCP Discover. Multicast is one sender to a group of receivers that asked to join, using addresses from 224.0.0.0/4 (224.0.0.0 to 239.255.255.255). Routing protocols use multicast: OSPF routers talk to 224.0.0.5, for example.

python
import ipaddress

for text in ["192.168.1.20", "127.0.0.1", "169.254.10.5", "224.0.0.5", "172.32.0.1"]:
    ip = ipaddress.ip_address(text)
    print(text, ip.is_loopback, ip.is_link_local, ip.is_multicast, ip in ipaddress.ip_network("172.16.0.0/12"))
The ipaddress module from the standard library knows the special ranges.
Tip: Python's is_private is broader than RFC 1918: it is True for any range that is not globally reachable, including the documentation ranges. If you want exactly the three RFC 1918 ranges, test membership in those three networks yourself.

Common mistakes

  • Giving a server on the internet a private address and wondering why nobody outside can reach it: private addresses need NAT to reach the internet.
  • Ignoring a 169.254.x.x address. It is a symptom, not a configuration: fix the DHCP problem (cable, VLAN, DHCP server, relay).
  • Saying 127.0.0.1 is the only loopback address. The whole 127.0.0.0/8 block is loopback.

Need help?

Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.

Try:

Watch the lesson

IPv4 address structure and special ranges · 1/8

IPv4 addresses

In this lesson we look at how an IPv4 address is built, and which ranges are special.

Prefer a video by a teacher? Find free videos on “ipv4 address classes private addresses rfc 1918 ccna” on YouTube ↗

In real life: APIPA at a hospital reception desk

A hospital in Chennai reports that the new reception PC "has internet on the cable but nothing works". The IT engineer runs ipconfig and sees 169.254.33.7. That APIPA address tells him at once that the PC never got an answer from the DHCP server. He checks the switch port and finds it in the wrong VLAN. After moving the port to the reception VLAN, the PC gets 10.20.5.41 from DHCP and the hospital software opens.

output
C:\> ipconfig
Ethernet adapter Ethernet:
   Autoconfiguration IPv4 Address. . : 169.254.33.7
   Subnet Mask . . . . . . . . . . . : 255.255.0.0
   Default Gateway . . . . . . . . . :
Windows: an APIPA address and no gateway means DHCP failed.

Practice (0/4 done)

Task 1 · Code · Python

Write ip_class(ip) that returns the old class letter "A", "B", "C", "D" or "E" from the first octet: 0 to 127 is A, 128 to 191 is B, 192 to 223 is C, 224 to 239 is D, 240 to 255 is E. Example: ip_class("172.16.0.1") returns "B".

Task 2 · Code · Python

Write classify(ip) that returns "loopback" (127.0.0.0/8), "link-local" (169.254.0.0/16), "multicast" (224.0.0.0/4), "private" (the three RFC 1918 ranges) or "public" for anything else. Use the ipaddress module and the in operator. Note: for this task treat every other address as "public", even the documentation ranges like 203.0.113.0/24 that real tools mark as special.

Task 3 · Question

A colleague says "all 172 addresses are private". Which of these addresses proves them wrong?

Task 4 · Practice

On your own computer, find your IPv4 address (ipconfig on Windows, ip addr or ifconfig on Linux and macOS). Write down the address, say whether it is private or public, which RFC 1918 range it is in, and which old class it would have been. Then ping 127.0.0.1 and explain what that test proves.

Quick quiz

Question 1

1.Which of these is NOT an RFC 1918 private range?

Question 2

2.A PC shows the address 169.254.12.9. What is the most likely cause?

Question 3

3.Which class did the address 130.5.6.7 belong to?

Question 4

4.What kind of address is 224.0.0.5?

Question 5

5.Why do private addresses and NAT exist?

Read more (free)

Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.

Which of these is NOT an RFC 1918 private range?

Answer: 169.254.0.0/16

169.254.0.0/16 is the link-local (APIPA) range, not one of the three RFC 1918 private ranges.

A PC shows the address 169.254.12.9. What is the most likely cause?

Answer: It could not get an address from a DHCP server

Windows and macOS give themselves an APIPA address from 169.254.0.0/16 when DHCP does not answer.

Which class did the address 130.5.6.7 belong to?

Answer: B

Class B first octets run from 128 to 191.

What kind of address is 224.0.0.5?

Answer: Multicast

224.0.0.0 to 239.255.255.255 (224.0.0.0/4) is multicast. 224.0.0.5 is used by OSPF routers.

Why do private addresses and NAT exist?

Answer: Because there are not enough public IPv4 addresses for every device

IPv4 has about 4.3 billion addresses, fewer than the number of devices. Private ranges are reused everywhere and NAT shares a few public addresses.

Which address is private?Related

Answer: 172.20.1.5

172.16.0.0/12 covers 172.16.x.x to 172.31.x.x, so 172.20.1.5 is private; 172.32.1.5 is not.

From IP addresses, subnets and CIDR

What is the network address of 192.168.5.130/25?Related

Answer: 192.168.5.128

/25 has a block size of 128. 130 is in 128 to 255, so the network is 192.168.5.128.

From Network, broadcast and usable host range

Which of these is a valid IPv4 address?Related

Answer: 172.16.254.1

172.16.254.1 has four parts, each from 0 to 255.

From Validating addresses and checking the same subnet

Which type of NAT lets hundreds of inside hosts share one public IP address?Related

Answer: PAT (NAT overload)

PAT uses port numbers to keep many conversations apart on one address.

From NAT and PAT

Pass the quiz (60% or more) or mark this topic as done when you are ready.

Your progress is saved on this device only.

Next steps

  1. 3 more topics in “IPv4 addressing” before its exam: Subnet masks, prefix length and wildcard masks, Network, broadcast and usable host range, Validating addresses and checking the same subnet.
  2. Module 3 exam: IPv4 addressing · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, Subnetting practice and IPv6. 57 topics left in the course before the final exam.

← Previous: Binary and decimal for networking