2 Networking Basics for IoT
Minimum Viable Understanding (MVU)
If you only have 5 minutes, here’s what you need to know about IoT networking:
- Networks use layers - The OSI (7 layers) and TCP/IP (4 layers) models organize how data travels from your sensor to the cloud
- Every device needs an address - IP addresses (like 192.168.1.100 for IPv4 or 2001:db8::1 for IPv6) identify devices on a network
- Protocols are the rules - MQTT, CoAP, and HTTP are common IoT protocols with different power/latency trade-offs
- Security is non-negotiable - Always use TLS encryption and proper credential management
- Choose protocols wisely - Battery-powered devices need low-power protocols like CoAP; always-on devices can use HTTP
Quick Decision: Need low power? Use CoAP over UDP. Need reliability? Use MQTT over TCP. Need simplicity? Use HTTP REST APIs.
Putting Numbers to It
The protocol decision can be quantified by payload efficiency and airtime.
\[ \eta = \frac{P}{P + O} \]
Where \(P\) is payload bytes and \(O\) is protocol overhead bytes.
Worked example: For a 20-byte sensor message:
\[ \begin{aligned} \eta_{\text{CoAP/UDP/IPv6}} &= \frac{20}{20 + (4+8+40)} = \frac{20}{72} = 27.8\%\\ \eta_{\text{MQTT/TCP/IPv6}} &= \frac{20}{20 + (2+20+40)} = \frac{20}{82} = 24.4\%\\ \eta_{\text{HTTP/TCP/IPv6}} &= \frac{20}{20 + 260} = 7.1\% \end{aligned} \]
At a 250 kbps radio, CoAP sends 72 bytes in about \((72\times 8)/250000 = 2.3\) ms, while HTTP sends 280 bytes in about 9.0 ms. Lower airtime usually means lower battery drain.
2.2 Learning Objectives
By the end of this chapter series, you will be able to:
- Explain Network Fundamentals: Summarize core networking concepts and apply them to real IoT system designs
- Differentiate OSI from TCP/IP: Compare the 7-layer OSI model with the 4-layer TCP/IP stack and classify which IoT protocols operate at each layer
- Select Appropriate Protocols: Evaluate and justify MAC and application protocol choices based on power budget, latency constraints, and device density requirements
- Configure IoT Devices: Build and troubleshoot ESP32 Wi-Fi connections using a systematic layer-by-layer diagnostic approach
- Implement Security Best Practices: Apply TLS encryption, credential management, and network segmentation to protect IoT deployments
For Beginners: Networking Basics
Networking is simply the art of getting devices to talk to each other. When your phone loads a webpage, dozens of networking rules work together behind the scenes – packaging data, finding routes, and confirming delivery. This chapter introduces those essential rules in plain language so you can understand how IoT devices stay connected.
Sensor Squad: What is IoT Networking?
Meet the Sensor Squad!
Sammy the Temperature Sensor, Lila the Light Sensor, Max the Motion Detector, and Bella the Button are tiny helpers living in a smart house. They need to send messages to a big computer in the cloud, but how do they do it?
The Post Office Analogy:
Think of networking like a postal system:
- IP Address = Your home address (so letters know where to go)
- Router = The local post office (sorts and sends letters)
- Internet = Mail trucks on highways (carrying letters between cities)
- Protocols = The rules for writing addresses correctly
When Sammy measures that the kitchen is too hot, he writes a digital “letter” with his message. The Wi-Fi helps send it to the router, then across the internet to the cloud. The cloud tells the oven to turn off, and the cookies are saved!
Lila’s Light Tip: “Different sensors use different ways to talk! I use Wi-Fi because I’m always plugged in, but Max uses Zigbee because he runs on batteries and needs to save power!”
Bella’s Button Fact: “Every device in your house has its own address number. Ask a grown-up to show you the ‘connected devices’ list on your Wi-Fi router - you might be surprised how many addresses there are!”
Try This at Home: Count how many smart devices you have (phones, tablets, smart TVs, game consoles). Each one has its own IP address!
2.3 Overview
Networking is the foundation of IoT. Without connectivity, you have isolated devices instead of the “Internet of Things.” This chapter series covers fundamental networking concepts essential for every IoT developer, from understanding the OSI model to configuring real devices.
Why This Matters:
- The majority of IoT deployment failures involve connectivity issues
- Understanding networking helps you debug problems faster
- Choosing the right protocol can extend battery life by 10x
- Security vulnerabilities often stem from poor network configuration
Chapter Series Structure
This topic has been organized into seven focused chapters for easier learning:
Core Learning:
- Introduction and Core Concepts (~25 min) - Network fundamentals, OSI/TCP-IP layers, IP addressing, network types
- Protocols and MAC Classification (~30 min) - Common IoT protocols by layer, MAC protocol taxonomy, protocol selection
- Hands-On Configuration (~35 min) - ESP32 configuration, port numbers, troubleshooting, security, bandwidth/latency
- Labs and Practice (~45 min) - Interactive labs, Python tools, hands-on exercises
Assessment and Reference:
- Assessment Overview (~5 min) - Assessment and reference index
- Knowledge Check (~15 min) - 10 self-assessment questions with detailed answers
- Reference and Glossary (~10 min) - Comprehensive MCQ quiz, terminology glossary, protocol tables
Estimated total time: 120-150 minutes
2.3.1 Chapter Relationships
2.4 Learning Path
2.4.1 Start Here: Introduction
Begin with Networking Basics: Introduction to learn:
- How network layers organize communication
- IPv4 vs IPv6 addressing and why IPv6 matters for IoT
- Common IoT network types (Wi-Fi, Bluetooth, Zigbee, LoRaWAN)
- Real-world example: How a smart thermostat sends data
2.4.2 Understand Protocols: MAC Classification
Continue to Networking Basics: Protocols and MAC to learn:
- Application, Network, and Data Link layer protocols
- Contention-based vs contention-free MAC protocols
- How to select the right MAC protocol for your use case
- Energy impact of protocol choices on battery life
2.4.3 Get Hands-On: Configuration and Troubleshooting
Move to Networking Basics: Hands-On Configuration to learn:
- ESP32 Wi-Fi configuration code
- Port numbers for MQTT, CoAP, HTTP and other IoT protocols
- Layer-by-layer troubleshooting methodology
- Essential security practices for IoT networks
- Bandwidth and latency optimization strategies
2.4.4 Practice: Labs
Continue with Networking Basics: Labs and Practice to:
- Build an ESP32 network diagnostics dashboard
- Create a Python network scanner for IoT devices
- Practice with hands-on coding exercises
2.4.5 Assess and Reference
Complete your learning with the Assessment and Reference section:
- Knowledge Check - 10 self-assessment questions with detailed explanations
- Reference and Glossary - Advanced MCQ quiz, terminology glossary, protocol comparison tables
2.5 Key Topics Covered
| Topic | Chapter | Description | Difficulty |
|---|---|---|---|
| OSI/TCP-IP Models | Introduction | 7-layer framework vs 4-layer practical model | Beginner |
| IP Addressing | Introduction | IPv4, IPv6, NAT, DHCP | Beginner |
| Network Types | Introduction | Wi-Fi, Bluetooth, Zigbee, LoRaWAN comparison | Beginner |
| Protocol Layers | Protocols | Application, Network, Data Link protocols | Intermediate |
| MAC Classification | Protocols | ALOHA, CSMA, TDMA, FDMA, Polling | Intermediate |
| ESP32 Configuration | Hands-On | Wi-Fi setup, diagnostics code | Intermediate |
| Port Numbers | Hands-On | MQTT (1883), CoAP (5683), HTTP (80) | Beginner |
| Troubleshooting | Hands-On | Layer-by-layer diagnostic approach | Intermediate |
| Security | Hands-On | TLS, credentials, segmentation | Intermediate |
| Practical Labs | Labs | ESP32 and Python hands-on exercises | Intermediate |
| Knowledge Check | Knowledge Check | 10 questions with detailed answers | All Levels |
| MCQ Quiz | Reference | Advanced scenario-based questions | Advanced |
| Glossary | Reference | 30+ networking terms with examples | Reference |
2.5.1 IoT Protocol Stack Overview
The following diagram illustrates how different IoT protocols map to network layers:
2.6 Prerequisites
Before starting this chapter series, you should be familiar with:
- Layered Network Models: Understanding the OSI and TCP/IP models
- Basic programming: Familiarity with C/C++ (for ESP32) or Python
- General IoT concepts: Basic understanding of what IoT devices are
2.8 Knowledge Check
Test your understanding of IoT networking basics with these questions:
Common Mistake: Confusing Bandwidth with Throughput in IoT System Design
The Mistake: Engineers specify “1 Mbps” Wi-Fi for a sensor network because the total data is 800 Kbps, assuming the link can handle it with 20% headroom.
Why It Fails: Bandwidth (1 Mbps) is the theoretical maximum, but actual throughput is always lower due to: 1. Protocol overhead: TCP/IP headers add 40-60 bytes per packet 2. MAC layer overhead: CSMA/CA backoff, ACKs, interframe spacing 3. Retransmissions: Packet loss at -75 dBm RSSI causes 5-10% retransmissions 4. Contention: Multiple devices sharing the channel
Real-World Example:
A warehouse deploys 50 temperature sensors on Wi-Fi 802.11n (theoretical 72 Mbps).
Calculation Error:
50 sensors × 100 bytes/packet × 1 packet/second = 5,000 bytes/sec = 40 Kbps
Engineer's conclusion: "40 Kbps is 0.05% of 72 Mbps bandwidth — plenty of headroom!"
What Actually Happens:
Wi-Fi 802.11n theoretical: 72 Mbps
Actual throughput with 20 devices: ~25 Mbps (65% efficiency loss)
With 50 devices competing: ~15 Mbps (80% efficiency loss)
At RSSI -75 dBm: ~8 Mbps (89% efficiency loss)
Even worse, at the application layer (goodput):
40 Kbps payload data
+ TCP/IP headers (40 bytes per 100-byte packet = 40% overhead)
+ Retransmissions (10% packet loss = 10% extra transmissions)
= ~62 Kbps actual required throughput
Result: The system experiences intermittent sensor dropouts during high contention periods, even though “40 Kbps << 72 Mbps”.
Correct Approach:
Step 1: Calculate actual throughput requirements (not just payload)
Application data: 40 Kbps
+ Transport overhead (TCP): ×1.4 = 56 Kbps
+ Retransmissions (10% loss): ×1.1 = 62 Kbps
+ MAC overhead (20%): ×1.2 = 74 Kbps
= Required throughput: ~75 Kbps
Step 2: Estimate realistic achievable throughput
Wi-Fi 802.11n at -75 dBm with 50 devices: ~8 Mbps actual
Safety margin (50% for future growth): 8 Mbps × 0.5 = 4 Mbps available
Step 3: Verify link budget
75 Kbps required << 4 Mbps available ✓
Link is viable with 50× margin
Key Lessons:
- Bandwidth ≠ Throughput: Expect 30-50% of theoretical bandwidth in typical IoT deployments
- Account for all layers: Application goodput requires 40-60% more throughput than payload suggests
- Plan for worst-case: Use RSSI -75 dBm, not -50 dBm, for link budget calculations
- Add margin: Design for 2-5× the calculated requirement to handle growth and degradation
Rule of Thumb: For IoT sensor networks, assume you’ll get 20-30% of the advertised wireless bandwidth at the application layer.
2.9 Practice Quizzes
Common Pitfalls
1. Using “Networking” and “Internet” Interchangeably
A network is any set of connected devices; the Internet is the global network using the TCP/IP protocol suite. An IoT deployment on a private subnet is a network but not the Internet. Fix: be precise about which network scope you are discussing.
2. Assuming a Router and a Switch Do the Same Job
A switch forwards based on MAC addresses within one subnet. A router forwards based on IP addresses between subnets. Fix: remember: switch = same subnet, router = different subnets.
3. Not Understanding That IoT Devices Need Networking Knowledge Too
IoT is fundamentally a networking discipline. A sensor without a correctly configured IP address, gateway, and DNS server cannot reach the cloud. Fix: treat networking fundamentals as a core IoT engineering skill, not an optional background topic.
2.10 Summary and Key Takeaways
Essential Networking Concepts for IoT
This chapter series provides a comprehensive foundation in IoT networking. The five concepts you must carry forward:
Layered Models Matter: The OSI (7 layers) and TCP/IP (4 layers) models organize communication functions and give you a systematic way to locate and fix problems.
Protocol Selection is Critical: Choosing MQTT vs CoAP vs HTTP affects power consumption, latency, and reliability – no single protocol fits all cases. Use the payload efficiency formula \(\eta = P/(P+O)\) to quantify the trade-off.
MAC Protocols Determine Efficiency: Contention-based (CSMA) vs contention-free (TDMA) protocols have fundamentally different power and latency trade-offs – match the MAC to your traffic pattern.
IPv6 is the Future: With 30+ billion IoT devices projected by 2030, IPv4’s 4.3 billion addresses are insufficient. Understand 6LoWPAN for constrained devices.
Security Must Be Built-In: TLS encryption, credential management, and network segmentation are non-negotiable for any production IoT deployment.
2.11 Quick Start
Ready to begin? Choose your entry point based on your experience level, then follow the learning path above in sequence:
| Your Background | Start Here |
|---|---|
| Complete beginner | Introduction – OSI model basics and IP addressing |
| Some networking experience | Protocols & MAC – protocol selection and trade-offs |
| Ready to build | Hands-On Configuration – ESP32 code and security |
| Prefer labs first | Labs and Practice – hands-on exercises |
Begin: Networking Basics Introduction
2.12 What’s Next
After completing this chapter series, continue your learning with these related topics:
| Topic | Chapter | Description |
|---|---|---|
| MQTT Fundamentals | MQTT Fundamentals | Deep dive into publish-subscribe messaging, QoS levels, and broker configuration for IoT |
| Wi-Fi Standards | Wi-Fi Fundamentals and Standards | 802.11 amendment history, channel planning, and ESP32 Wi-Fi configuration in depth |
| LoRaWAN Networking | LoRaWAN Overview | Long-range, low-power wide-area networking — device classes, spreading factors, and gateway architecture |
| IoT Security | IoT Security Fundamentals | Threat modelling, TLS configuration, credential management, and network segmentation for production deployments |
| CoAP Protocol | CoAP Fundamentals | Constrained Application Protocol architecture, observe mode, and DTLS security for battery-powered devices |
| Network Topologies | IoT Protocols Overview | Survey of the full IoT protocol landscape across all OSI layers and wireless technologies |