22  IPv4 Addressing Fundamentals

Key Concepts
  • IPv4: Internet Protocol version 4; uses 32-bit addresses (4 bytes) providing approximately 4.3 billion unique addresses
  • Dotted-Decimal Notation: The human-readable representation of IPv4 addresses as four decimal octets (e.g., 192.168.1.100)
  • Subnet Mask: A 32-bit value that separates the network portion from the host portion of an IPv4 address
  • CIDR (Classless Inter-Domain Routing): Address notation using a prefix length (e.g., 192.168.1.0/24) instead of classful subnet masks
  • Private Address Ranges: Reserved IPv4 ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) not routed on the public internet; used in private networks
  • Broadcast Address: The highest address in a subnet (host bits all 1s); packets sent here reach all hosts in the subnet
  • Network Address: The lowest address in a subnet (host bits all 0s); identifies the subnet itself, not a host

22.1 In 60 Seconds

An IPv4 address is a 32-bit number written as four octets (e.g., 192.168.1.100) that uniquely identifies a device on a network. For IoT deployments, use private address ranges (10.x.x.x, 172.16-31.x.x, 192.168.x.x) to avoid conflicts with public internet addresses, and understand that the 4.3 billion IPv4 address limit is a key driver for IPv6 adoption.

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:

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.

“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.”


IPv4 packet header diagram showing all 20 bytes of fields: Version (4 bits), IHL (4 bits), DSCP/ECN (8 bits), Total Length (16 bits), Identification (16 bits), Flags (3 bits), Fragment Offset (13 bits), TTL (8 bits), Protocol (8 bits), Header Checksum (16 bits), Source IP (32 bits), and Destination IP (32 bits). Optional fields extend beyond 20 bytes as indicated by IHL

IPv4 Packet Header Fields
Figure 22.1: IPv4 packet header structure showing the 20-byte minimum header with all fields that control packet routing, fragmentation, and delivery. The TTL field prevents infinite routing loops, while Protocol identifies the payload type (TCP=6, UDP=17, ICMP=1).

IPv4 subnet masking diagram showing how a 32-bit subnet mask divides an IP address into network portion and host portion. Example shows 192.168.1.100 with mask 255.255.255.0 (/24), where network portion is 192.168.1.0 and host portion allows addresses 1-254. Demonstrates bitwise AND operation between IP address and subnet mask

IPv4 Subnet Mask Visualization
Figure 22.2: Subnet masks divide IP addresses into network and host portions. The /24 mask (255.255.255.0) provides 254 usable host addresses, commonly used for small office or residential networks.

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.

IPv4 address structure showing 192.168.1.100 divided into four 8-bit octets with decimal and binary representations for each octet
Figure 22.3: IPv4 address 192.168.1.100 structure showing four octets in decimal and binary

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

Try It: Octet Binary Converter

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.

IPv4 address classes diagram showing Class A (1-126, /8, large), Class B (128-191, /16, medium), Class C (192-223, /24, small), Class D (224-239, multicast), and Class E (240-255, reserved)
Figure 22.4: IPv4 address classes A through E with range, mask, and host capacity

This variant shows address class selection as a decision process based on the number of hosts needed:

Decision tree for IPv4 address class selection based on number of hosts needed: fewer than 254 hosts uses Class C, fewer than 65,534 uses Class B, more than 65,534 uses Class A, illustrating why classful addressing wasted address space

IPv4 address class selection decision tree by host count

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:

  1. Use 192.168.x.x for small deployments: Home automation, single-building smart systems
  2. Use 10.x.x.x for large deployments: Campus-wide sensor networks, smart city infrastructure
  3. Reserve dedicated subnets per device type: Separate cameras, sensors, controllers for security and management
  4. Document your addressing scheme: Critical for troubleshooting multi-thousand device networks
Worked Example: IP Address Plan for a Smart Factory

Scenario: A manufacturing company is deploying IoT across a 3-building campus. Each building has 4 floors. They need to design an IPv4 addressing scheme using the 10.0.0.0/8 private range.

Step 1: Inventory devices per floor

Device Type Per Floor Per Building Campus Total
PLCs (programmable logic controllers) 8 32 96
Temperature/humidity sensors 40 160 480
Security cameras 12 48 144
Access control panels 6 24 72
Network switches/APs 4 16 48
Floor total 70 280 840

Step 2: Design addressing hierarchy

Scheme: 10.BUILDING.FLOOR_DEVICETYPE.HOST

Building 1 = 10.1.x.x
Building 2 = 10.2.x.x
Building 3 = 10.3.x.x

Within each building:
  Floor 1, PLCs:       10.B.10.0/28  (14 usable, need 8)
  Floor 1, Sensors:    10.B.11.0/26  (62 usable, need 40)
  Floor 1, Cameras:    10.B.12.0/28  (14 usable, need 12)
  Floor 1, Access:     10.B.13.0/29  (6 usable, need 6)
  Floor 1, Network:    10.B.14.0/29  (6 usable, need 4)

  Floor 2: 10.B.20-24.x (same pattern)
  Floor 3: 10.B.30-34.x
  Floor 4: 10.B.40-44.x

Step 3: Verify the plan

Check Calculation Result
Addresses per floor 14 + 62 + 14 + 6 + 6 = 102 usable 70 devices + 32 growth buffer
Growth headroom (102 - 70) / 70 = 46% Exceeds 30% minimum
Total subnets 3 buildings x 4 floors x 5 types = 60 Manageable for firewall rules
Address space used 840 devices in 10.0.0.0/8 (16.7M addresses) 0.005% utilized, ample room

Step 4: Security benefit

Firewall rule: DENY 10.1.12.0/28 -> 10.1.11.0/26 blocks cameras from accessing sensor data. Without subnetting, this isolation is impossible – a compromised camera could sniff all traffic on a flat network.

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 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:

MAC address collision probability diagram showing that with random assignment, collisions become likely at square root of address space (16.7 million devices), while structured IEEE OUI assignment prevents collisions
Figure 22.5: Birthday problem for MAC addressing: random vs structured OUI block assignment

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

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.

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.

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