22 IPv4 Addressing Fundamentals
22.2 Learning Objectives
By the end of this chapter, you will be able to:
- Interpret IPv4 address structure: Analyze 32-bit addresses in dotted-decimal and binary notation, converting between representations
- Classify address ranges: Differentiate historical Class A, B, C, D, and E address ranges by first-octet values and their characteristics
- Apply private IP ranges: Select and configure RFC 1918 addresses for internal IoT networks to prevent public routing conflicts
- Differentiate special-purpose addresses: Explain the role of loopback, link-local, and broadcast addresses in network operations
MVU: Minimum Viable Understanding
Core concept: An IPv4 address is a 32-bit unique identifier for a device on a network, written as four numbers (0-255) separated by dots like 192.168.1.100.
Why it matters: Every device on a network needs a unique IP address to communicate - incorrect addressing causes silent failures with no helpful error messages.
Key takeaway: Use private IP ranges (10.x.x.x, 172.16-31.x.x, 192.168.x.x) for internal IoT networks to avoid conflicts with public internet addresses.
22.3 Prerequisites
Before diving into this chapter, you should be familiar with:
- Networking Basics: Foundation in networking concepts and protocol basics
- Layered Network Models: Understanding where addressing operates within the OSI/TCP-IP models (Layer 3 - Network Layer)
For Beginners: IP Addressing Basics
Imagine mailing a letter: you need a street address to identify the building. IP addressing works the same way - every device on a network needs a unique IP address.
IPv4 addresses look like 192.168.1.100 - four numbers separated by dots. Each number ranges from 0 to 255 because each is stored in 8 bits (2^8 = 256 possible values).
Private IP ranges are special addresses reserved for internal networks: - 10.0.0.0 - 10.255.255.255 (large organizations) - 172.16.0.0 - 172.31.255.255 (medium networks) - 192.168.0.0 - 192.168.255.255 (home/small office)
These addresses work within your local network but cannot be used directly on the public internet.
Sensor Squad: The Number Game!
“My address is 192.168.1.42,” announced Sammy the Sensor. “But what do those numbers actually mean?” Max the Microcontroller explained, “Each number is one byte – 8 bits. Four bytes make 32 bits total. That is why each number goes from 0 to 255 – it is all the combinations you can make with 8 bits!”
“The first part tells you which NETWORK you are on, and the last part is YOUR specific device number,” added Lila the LED. “So 192.168.1 is the neighborhood, and 42 is your house number. Every device in our smart building shares the 192.168.1 part, but each has a different last number.”
“We use special private addresses that start with 10, 172.16, or 192.168,” Max continued. “These are reserved for internal networks like ours. The public internet uses different numbers, and our router translates between them.”
“Here is the big problem though,” said Bella the Battery. “IPv4 only has about 4.3 billion possible addresses. There are already over 15 billion IoT devices in the world! We are running out of addresses, which is why IPv6 was invented with practically unlimited addresses. But for now, private addressing and NAT keep us going.”
22.4 Address Structure and Binary Representation
An IPv4 address consists of 32 bits divided into four 8-bit octets, typically written in dotted-decimal notation. Understanding the binary representation is crucial for subnetting calculations.
Binary to Decimal Conversion:
Each octet can represent values from 0 to 255 (2^8 - 1). The binary positions represent powers of 2:
| Position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Example: 192 in binary = 11000000 = 128 + 64 = 192
Putting Numbers to It
Each octet position represents a power of 2. The octet value 192 breaks down as:
\[192 = 2^7 \times 1 + 2^6 \times 1 + 2^5 \times 0 + ... + 2^0 \times 0\] \[192 = 128 + 64 + 0 + ... + 0\]
For the full address 192.168.1.100: - Octet 1: \(192 = 11000000_2\) - Octet 2: \(168 = 10101000_2 = 128 + 32 + 8\) - Octet 3: \(1 = 00000001_2\) - Octet 4: \(100 = 01100100_2 = 64 + 32 + 4\)
This 32-bit representation gives IPv4 its maximum address space: \[2^{32} = 4{,}294{,}967{,}296 \text{ addresses}\]
With 8 billion people on Earth, that’s only 0.54 addresses per person — why IPv4 exhaustion drives IoT to IPv6.
22.5 Address Classes (Historical Context)
Before CIDR (Classless Inter-Domain Routing), IPv4 addresses were organized into classes. While mostly obsolete, understanding classes provides historical context and helps identify network ranges.
Alternative View: Address Class Selection by Network Size
This variant shows address class selection as a decision process based on the number of hosts needed:
While address classes are historical, this decision tree helps understand why CIDR replaced them - classful addressing often wasted addresses by allocating too many for actual needs.
| Class | First Octet Range | Default Mask | Networks | Hosts per Network | Typical Use |
|---|---|---|---|---|---|
| A | 1-126 | 255.0.0.0 (/8) | 126 | 16,777,214 | Large organizations |
| B | 128-191 | 255.255.0.0 (/16) | 16,384 | 65,534 | Medium organizations |
| C | 192-223 | 255.255.255.0 (/24) | 2,097,152 | 254 | Small networks |
| D | 224-239 | N/A | N/A | N/A | Multicast |
| E | 240-255 | N/A | N/A | N/A | Reserved/Experimental |
Why 127.x.x.x is Missing
The range 127.0.0.0/8 is reserved for loopback addresses. 127.0.0.1 (localhost) is used for a device to communicate with itself, essential for testing and local services.
22.6 Private IP Address Ranges (RFC 1918)
IoT deployments almost exclusively use private IP ranges for internal device networks, with NAT providing internet access when needed.
| Range | CIDR | Class Equivalent | Total Addresses | Common IoT Use Cases |
|---|---|---|---|---|
| 10.0.0.0 - 10.255.255.255 | 10.0.0.0/8 | 1 Class A | 16,777,216 | Large enterprise IoT deployments, smart cities |
| 172.16.0.0 - 172.31.255.255 | 172.16.0.0/12 | 16 Class B | 1,048,576 | Medium-sized industrial IoT networks |
| 192.168.0.0 - 192.168.255.255 | 192.168.0.0/16 | 256 Class C | 65,536 | Home automation, small commercial buildings |
IoT Addressing Best Practices:
- Use 192.168.x.x for small deployments: Home automation, single-building smart systems
- Use 10.x.x.x for large deployments: Campus-wide sensor networks, smart city infrastructure
- Reserve dedicated subnets per device type: Separate cameras, sensors, controllers for security and management
- Document your addressing scheme: Critical for troubleshooting multi-thousand device networks
22.7 Special-Purpose IPv4 Addresses
| Address/Range | Purpose | Example Use in IoT |
|---|---|---|
| 0.0.0.0 | Default route, unknown address | DHCP client before receiving IP |
| 127.0.0.0/8 | Loopback (localhost) | Local MQTT broker testing |
| 169.254.0.0/16 | Link-local (APIPA) | Auto-configuration when DHCP fails |
| 224.0.0.0/4 | Multicast | mDNS, device discovery protocols |
| 255.255.255.255 | Limited broadcast | DHCP discovery messages |
The Birthday Problem for MAC Addressing: Why Structured Addressing Matters
The surprising collision risk:
You might think with 2^48 MAC addresses (281 trillion), collisions would be rare. But the Birthday Paradox reveals a counterintuitive truth.
The Birthday Problem: In a room of just 23 people, there’s a 50% chance two share a birthday. Why? Because we’re comparing all possible pairs, not individuals against a specific date.
Applied to MAC addresses:
The Math:
- Address space: 2^48 ≈ 281 trillion addresses
- Birthday paradox formula: P(collision) ≈ 1 - e^(-n²/2m), where n = devices, m = address space
- 50% collision threshold: √(2m ln 2) ≈ 19.8 million devices (roughly 2^24.2)
- Reality: Large IoT networks already exceed this threshold
Why random MAC assignment fails:
If manufacturers assigned MAC addresses randomly (using P ≈ 1 - e^(-n²/2m)): - Smart city with 5 million sensors: ~4.3% collision probability - Factory with 100,000 devices: ~0.002% collision probability (small, but 1 collision = network chaos) - Global IoT (15 billion devices): ~100% collision probability (guaranteed collisions)
How structured addressing solves this:
IEEE assigns OUI blocks (Organizationally Unique Identifier): - First 24 bits = manufacturer ID (assigned by IEEE) - Last 24 bits = device serial (assigned by manufacturer) - Result: Each manufacturer has 16.7 million unique addresses
Example:
Cisco OUI: 00:1E:14:xx:xx:xx
Arduino OUI: A4:CF:12:xx:xx:xx
Espressif OUI: 24:0A:C4:xx:xx:xx
Key takeaway: Address space size alone doesn’t prevent collisions. Without structured assignment, collisions occur at √N, not N. This is why MAC addresses, Bluetooth IDs, and device identifiers all use manufacturer-assigned blocks rather than random generation.
Common Pitfalls
1. Confusing Network Address, Broadcast Address, and Host Addresses
For 192.168.1.0/24: 192.168.1.0 is the network address (unusable), 192.168.1.255 is the broadcast (unusable), and 192.168.1.1–192.168.1.254 are host addresses. Fix: always identify and exclude the network and broadcast addresses before counting usable host addresses.
2. Not Planning IPv4 Address Space for IoT Scale
A /24 subnet provides 254 usable host addresses. A 300-device IoT deployment needs a /23 (510 hosts). Running out of addresses after deployment is expensive to fix. Fix: estimate the maximum device count including 50% growth headroom and size the subnet accordingly before deployment.
3. Using Public IP Addresses for Private IoT Networks
Assigning public IP addresses to internal IoT sensors wastes public address space and exposes devices directly to the internet. Fix: use RFC 1918 private address ranges for internal IoT networks and use NAT at the gateway.
22.8 Summary
- IPv4 addresses are 32-bit identifiers written as four decimal numbers (0-255) separated by dots, like 192.168.1.100
- Binary conversion is essential for subnetting: each octet represents 8 bits with positional values from 128 to 1
- Historical address classes (A, B, C) defined network sizes but have been replaced by flexible CIDR notation
- Private IP ranges (10.x.x.x, 172.16-31.x.x, 192.168.x.x) are reserved for internal networks and cannot be routed on the public internet
- Special addresses like loopback (127.0.0.1), link-local (169.254.x.x), and broadcast (255.255.255.255) serve specific network functions
- Structured addressing (like IEEE OUI for MAC addresses) prevents collisions in large-scale deployments
22.9 What’s Next
Now that you can interpret IPv4 address fundamentals and apply private addressing to IoT networks, continue with the following chapters:
| Topic | Chapter | Description |
|---|---|---|
| Subnetting and CIDR | Subnetting and CIDR | Calculate subnet boundaries, determine usable host counts, and apply CIDR notation to divide IoT networks into manageable segments |
| Ports and NAT | Ports and NAT | Configure port numbers that identify services on a device and understand how NAT translates private addresses to enable internet connectivity |
| IPv6 for IoT | IPv6 for IoT | Analyze the 128-bit addressing scheme that eliminates IPv4 exhaustion and evaluate its advantages for large-scale IoT deployments |
| Network Basics | Networking Basics | Review foundational networking concepts including OSI layers, protocol stacks, and the role of addressing at Layer 3 |
| DNS and Name Resolution | DNS and Name Resolution | Examine how domain names are translated to IP addresses and how mDNS enables IoT device discovery without a central DNS server |