Beginner · IPv4 addressing · topic 12 of 57 · 30 min
IPv4 address structure and special ranges
Explanation
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.
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.
| Class | First octet | Leading bits | Default mask | Used for |
|---|---|---|---|---|
| A | 1 to 126 (0 and 127 reserved) | 0 | 255.0.0.0 (/8) | Very large networks |
| B | 128 to 191 | 10 | 255.255.0.0 (/16) | Medium networks |
| C | 192 to 223 | 110 | 255.255.255.0 (/24) | Small networks |
| D | 224 to 239 | 1110 | none | Multicast |
| E | 240 to 255 | 1111 | none | Experimental, 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.
| Range | Covers | Typical use |
|---|---|---|
| 10.0.0.0/8 | 10.0.0.0 to 10.255.255.255 | Large companies, banks, cloud VPCs |
| 172.16.0.0/12 | 172.16.0.0 to 172.31.255.255 | Medium networks, Docker default networks |
| 192.168.0.0/16 | 192.168.0.0 to 192.168.255.255 | Homes and small offices |
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.
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"))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
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.
C:\> ipconfig
Ethernet adapter Ethernet:
Autoconfiguration IPv4 Address. . : 169.254.33.7
Subnet Mask . . . . . . . . . . . : 255.255.0.0
Default Gateway . . . . . . . . . :Practice (0/4 done)
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".
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.
A colleague says "all 172 addresses are private". Which of these addresses proves them wrong?
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
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Subnet masks, prefix length and wildcard masksIPv4 addressing · same module
- Network, broadcast and usable host rangeIPv4 addressing · same module
- IP addresses, subnets and CIDRCyber Security: from zero to SOC analyst · Networking for security
- NAT and PATIP services: DHCP, DNS, NAT and more
- IPv6 address types, EUI-64, SLAAC and NDPSubnetting practice and IPv6
- DHCP: automatic addressesIP services: DHCP, DNS, NAT and more
Questions people ask about this
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.
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.
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.
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
- 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.
- Module 3 exam: IPv4 addressing · 13 questions · 20 min, without help. 5 topics of this module still to finish first.
- Then the next module, Subnetting practice and IPv6. 57 topics left in the course before the final exam.