21 Addressing & Subnetting
21.2 Overview
This comprehensive guide to IP addressing and subnetting has been organized into focused chapters for easier learning. Each chapter covers a specific aspect of network addressing essential for IoT deployments.
MVU: Minimum Viable Understanding
Core concept: Every device on a network needs a unique IP address, and subnets divide large networks into manageable segments using masks that separate the “network” from “host” portions of addresses.
Why it matters: Incorrect IP addressing causes silent failures – devices simply cannot communicate, with no helpful error messages to diagnose the problem.
Key takeaway: Use private IP ranges (10.x.x.x, 172.16-31.x.x, 192.168.x.x) for internal IoT networks, and plan /24 subnets (254 hosts) per floor, building, or sensor type.
How It Works: IP Addressing and Subnetting
Addressing and subnetting work together to organize devices on networks:
Step 1: Address Assignment – Each device receives a unique IP address (either via DHCP or static configuration)
Step 2: Subnet Mask Application – The subnet mask divides the IP into network and host portions (e.g., 192.168.1.100 with mask 255.255.255.0 means network=192.168.1.0, host=.100)
Step 3: Local vs Remote Decision – Device performs bitwise AND between destination IP and its subnet mask to determine if destination is on the same network
Step 4: Routing Decision – If destination is local (same network), use ARP to find MAC and send directly. If remote (different network), send to default gateway
Step 5: Gateway Forwarding – Router examines destination IP, consults routing table, and forwards packet toward destination network
Example: Device at 192.168.1.50/24 sends to 192.168.1.100 – same network (192.168.1.0), sends directly. Sends to 10.0.0.5 – different network, forwards to gateway at 192.168.1.1.
21.3 Chapter Guide
Select the chapter that matches your learning goals:
21.3.1 IPv4 Addressing Fundamentals
Topics: 32-bit address structure, binary conversion, address classes (historical), private IP ranges (RFC 1918), special-purpose addresses, MAC address OUI
Best for: Understanding the building blocks of IP addressing
21.3.2 Subnetting and CIDR
Topics: Subnet masks, network/host division, CIDR notation, calculating network and broadcast addresses, VLSM, IoT subnet design patterns
Best for: Learning to divide networks and plan efficient address allocation
21.3.3 Port Numbers and NAT
Topics: Port number ranges (well-known, registered, ephemeral), IoT protocol ports (MQTT, CoAP, HTTP), 5-tuple connections, NAT translation, NAT traversal patterns for IoT
Best for: Understanding service identification and internet connectivity for IoT
21.3.4 IPv6 for IoT
Topics: 128-bit addresses, compression rules, address types (global, link-local, unique-local), 6LoWPAN header compression, SLAAC, IPv4/IPv6 transition strategies
Best for: Preparing for next-generation IoT networks and Thread/Matter protocols
21.3.5 DHCP and Address Resolution
Topics: DHCP DORA process, lease management, DHCP options, DHCP reservations, ARP for IPv4, Neighbor Discovery for IPv6, troubleshooting IP conflicts
Best for: Configuring automatic IP assignment and understanding address resolution
21.4 Learning Objectives (Complete Guide)
By completing all chapters, you will be able to:
- Assign IP Addresses: Configure IPv4 and IPv6 addresses for IoT devices and networks
- Design Subnets: Calculate subnet masks and plan network segmentation for IoT deployments
- Configure Port Numbers: Identify and use standard ports for IoT protocols (MQTT, CoAP, HTTP)
- Implement NAT and DHCP: Set up address translation and automatic IP assignment for device networks
- Plan Private Networks: Design internal networks using RFC 1918 private address ranges
- Troubleshoot Addressing Issues: Diagnose IP conflicts, routing problems, and connectivity failures
For Beginners: Network Addressing and Subnetting
Every device on a network needs a unique address, just like every house needs a street address for mail delivery. Subnetting is the practice of dividing a large network into smaller sections, like dividing a city into neighborhoods. This makes it easier to manage traffic and keep things organized.
Sensor Squad: The Neighborhood Map!
“How does the network know where to send my data?” asked Sammy the Sensor. Max the Microcontroller drew a map. “Every device gets a unique IP address, like a house number. And subnetting divides the big network into neighborhoods so messages get delivered to the right area first.”
“Think of it like a school,” said Lila the LED. “The school is the network (10.0.0.0), each floor is a subnet (10.0.1.0 for floor one, 10.0.2.0 for floor two), and each classroom door has a number. If you want to find room 203, you go to floor 2 first, then find room 03.”
“In our smart building, we put all temperature sensors on one subnet, all motion detectors on another, and all cameras on a third,” Max continued. “That way, if the cameras send lots of video data, it does not clog up the subnet where our little temperature readings travel.”
Bella the Battery appreciated this. “Smaller subnets also mean fewer devices shouting broadcast messages to everyone, which saves energy. And if a security problem hits one subnet, the other subnets stay safe. Subnetting is like building walls between neighborhoods – good for traffic, good for security!”
21.5 Prerequisites
Before diving into these chapters, you should be familiar with:
- Networking Basics: Foundation in networking concepts, IP addressing fundamentals, and protocol basics
- Network Mechanisms: Understanding how datagrams, packet switching, and network communication work
- Layered Network Models: Knowledge of where addressing operates within the OSI/TCP-IP models (primarily Layer 3 – Network Layer)
21.6 Quick Reference
21.6.1 Private IP Ranges (RFC 1918)
| Range | CIDR | Addresses | Typical Use |
|---|---|---|---|
| 10.0.0.0 – 10.255.255.255 | /8 | 16,777,216 | Large enterprise, smart cities |
| 172.16.0.0 – 172.31.255.255 | /12 | 1,048,576 | Medium industrial networks |
| 192.168.0.0 – 192.168.255.255 | /16 | 65,536 | Home automation, small buildings |
21.6.2 Common IoT Ports
| Protocol | Port | Transport | Use Case |
|---|---|---|---|
| MQTT | 1883 | TCP | Lightweight messaging |
| MQTT/TLS | 8883 | TCP | Secure MQTT |
| CoAP | 5683 | UDP | Constrained devices |
| HTTP | 80 | TCP | Web interfaces |
| HTTPS | 443 | TCP | Secure web/APIs |
21.6.3 Subnet Quick Reference
| CIDR | Usable Hosts | Use Case |
|---|---|---|
| /30 | 2 | Point-to-point links |
| /28 | 14 | Small room automation |
| /27 | 30 | Single floor |
| /26 | 62 | Medium building floor |
| /24 | 254 | Standard building network |
| /22 | 1,022 | Large campus |
21.7 Knowledge Check
Level 1: Beginner Example – Home Network Addressing
Scenario: Set up IP addresses for 5 smart home devices
Given: Router at 192.168.1.1, subnet mask 255.255.255.0 (/24)
Address Plan:
- Smart thermostat: 192.168.1.10 (static, always at this address)
- Security camera: 192.168.1.20 (static)
- 3 sensors: 192.168.1.100-102 (DHCP range)
Why This Works: Static IPs for devices you access directly (thermostat, camera), DHCP for sensors that just report data.
Level 2: Intermediate Example – Multi-Floor Building
Scenario: 3-floor building, 30 devices per floor, need isolation
Address Plan:
- Floor 1: 10.1.1.0/24 (254 usable IPs, 30 devices + 224 buffer)
- Floor 2: 10.1.2.0/24
- Floor 3: 10.1.3.0/24
Benefits: Each floor is a separate subnet – broadcasts stay within the floor, firewall rules can isolate floors, and it is easy to identify which floor a device is on from its IP.
Level 3: Advanced Example – VLSM for Mixed Device Types
Scenario: Smart factory with different device densities
Given: 10.50.0.0/22 (1,022 usable addresses to allocate)
VLSM Allocation:
- 200 PLCs: 10.50.0.0/24 (254 usable addresses)
- 50 cameras: 10.50.1.0/26 (62 usable addresses)
- 30 access points: 10.50.1.64/27 (30 usable addresses)
- 10 servers: 10.50.1.96/28 (14 usable addresses)
- Reserved for growth: 10.50.2.0/23 (510 usable addresses)
Why VLSM?: Different device types get appropriately sized subnets – no waste, efficient use of address space.
21.8 Concept Relationships
| Concept | Depends On | Enables | Common With |
|---|---|---|---|
| Subnetting | IP addresses, subnet masks | Network segmentation, security isolation | VLANs, routing |
| CIDR Notation | Binary representation | Efficient address allocation | VLSM, route aggregation |
| Private IP Ranges | RFC 1918 standard | Internal networks without public IPs | NAT, firewalls |
| Subnet Mask | Binary AND operation | Local vs remote routing decisions | Default gateway configuration |
| VLSM | Subnetting fundamentals | Variable-sized subnets | Efficient address utilization |
Try It Yourself: Subnet Planning Exercise
Exercise: Plan subnets for a university campus IoT deployment
Given:
- IP allocation: 10.100.0.0/16 (65,534 usable addresses)
- 5 buildings: Library, Science, Admin, Dorms, Sports Center
- Devices per building: 50–300 IoT sensors, cameras, access points
Task 1: Calculate Building Needs
- Library: 150 devices
- Science: 300 devices (labs have many sensors)
- Admin: 50 devices
- Dorms: 200 devices
- Sports: 100 devices
Task 2: Add 30% Growth Buffer
- Library: 150 x 1.3 = 195 – need /24 (254 usable addresses)
- Science: 300 x 1.3 = 390 – need /23 (510 usable addresses)
- Admin: 50 x 1.3 = 65 – need /25 (126 usable addresses)
- Dorms: 200 x 1.3 = 260 – need /23 (510 usable addresses)
- Sports: 100 x 1.3 = 130 – need /24 (254 usable addresses)
Task 3: Assign Subnets (Largest First)
- Science: 10.100.0.0/23 (390 devices, 510 available)
- Dorms: 10.100.2.0/23 (260 devices, 510 available)
- Library: 10.100.4.0/24 (195 devices, 254 available)
- Sports: 10.100.5.0/24 (130 devices, 254 available)
- Admin: 10.100.6.0/25 (65 devices, 126 available)
Putting Numbers to It
Calculating usable addresses requires accounting for network and broadcast addresses.
\(\text{Usable Addresses} = 2^{(32-\text{prefix})} - 2\)
Worked example for /24: \(2^{(32-24)} - 2 = 2^8 - 2 = 256 - 2 = 254\) usable addresses
For Dorms (260 devices needed):
- /24 provides: 254 addresses (short by 6)
- /23 provides: \(2^9 - 2 = 510\) addresses (fits with margin)
- Cost of wrong sizing: 6 devices cannot connect, requiring emergency network redesign
Verification:
- Total used: 510 + 510 + 254 + 254 + 126 = 1,654 addresses
- Total available: 65,534
- Utilization: 2.5% (plenty of room for expansion)
Common Mistake: Confusing /31 and /30 for Point-to-Point Links
The Mistake: “I only need 2 addresses for a point-to-point link between routers, so I will use a /32 subnet.”
Why It Fails: A /32 designates a single host address (\(2^0 = 1\)), not a subnet with two endpoints.
The Numbers:
- /32: 1 address (single host, unusable as a subnet)
- /31: 2 addresses (valid for point-to-point links per RFC 3021, widely supported by modern routers)
- /30: 4 addresses, 2 usable (\(2^2 - 2 = 2\)) – the traditional choice
Traditional /30 approach (universally supported):
- Network: 192.168.1.0 (unusable)
- Router A: 192.168.1.1 (usable)
- Router B: 192.168.1.2 (usable)
- Broadcast: 192.168.1.3 (unusable)
Modern /31 approach (RFC 3021, saves address space):
- Router A: 192.168.1.0
- Router B: 192.168.1.1
- No network or broadcast address reserved
Recommendation: Use /31 if your equipment supports RFC 3021 (most modern routers do). Otherwise, use /30. Never use /32 for a point-to-point link.
21.9 Practice Quizzes
Common Pitfalls
1. Planning Subnets Based on Current Device Count Only
IoT networks grow unpredictably. A subnet with 10 free addresses today may be exhausted in 6 months as more sensors are added. Fix: plan for 3–5× current capacity, using /22 or larger subnets for IoT VLANs that are expected to grow.
2. Putting All IoT Devices on the Same Subnet as IT Equipment
IoT devices are often less secure than IT equipment. A compromised sensor could attack servers on the same subnet. Fix: isolate IoT devices in a dedicated subnet/VLAN with firewall rules limiting their access to only the specific servers they need to reach.
3. Not Documenting the Addressing Scheme
Over time, addresses are assigned informally and the subnet fills unpredictably. Fix: maintain an IP Address Management (IPAM) spreadsheet or tool documenting every assigned address, device name, and MAC address.
21.10 What’s Next
After completing IP addressing and subnetting, continue with these related chapters:
| Topic | Chapter | Description |
|---|---|---|
| Routing | Routing Fundamentals | Learn how routers use subnet information to forward packets between networks |
| Transport Layer | Transport Fundamentals | Understand TCP and UDP transport protocols that operate above the network layer |
| IoT Messaging | MQTT Fundamentals | Apply networking knowledge to IoT publish-subscribe messaging with port 1883 |
| Networking Basics | Networking Basics | Review foundational networking concepts and topologies that underpin addressing |
| Network Models | Layered Network Models | Understand where IP addressing fits within the OSI and TCP/IP model layers |
| Hands-On Practice | Networking Labs and Quiz | Hands-on configuration exercises for subnetting and address planning |