2  Networking Basics for IoT

Key Concepts
  • Networking: The practice of connecting computing devices so they can exchange data and share resources
  • Network Topology: The physical or logical arrangement of network nodes and connections
  • TCP/IP: The Transmission Control Protocol / Internet Protocol suite; the foundational protocol stack for the internet and most IoT systems
  • Packet: A formatted unit of data carried over a network; contains header (control information) and payload (application data)
  • Router: A network device that forwards packets between different IP subnets based on routing table entries
  • Switch: A network device that forwards frames within a LAN based on MAC addresses, creating separate collision domains per port
  • Firewall: A network security device that filters traffic based on configured rules, typically placed between IoT device networks and the internet

2.1 In 60 Seconds

IoT networking is built on layered models (OSI 7-layer, TCP/IP 4-layer) that organize how sensor data travels from device to cloud. Protocol choice is driven by trade-offs: use CoAP over UDP for battery-powered devices needing low power, MQTT over TCP for reliable message delivery, or HTTP REST for simplicity when power is not constrained.

Minimum Viable Understanding (MVU)

If you only have 5 minutes, here’s what you need to know about IoT networking:

  1. Networks use layers - The OSI (7 layers) and TCP/IP (4 layers) models organize how data travels from your sensor to the cloud
  2. 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
  3. Protocols are the rules - MQTT, CoAP, and HTTP are common IoT protocols with different power/latency trade-offs
  4. Security is non-negotiable - Always use TLS encryption and proper credential management
  5. 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.

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.

Try It: Protocol Efficiency Calculator

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

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.


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
Quick Check: Protocol Selection

Chapter Series Structure

This topic has been organized into seven focused chapters for easier learning:

Core Learning:

  1. Introduction and Core Concepts (~25 min) - Network fundamentals, OSI/TCP-IP layers, IP addressing, network types
  2. Protocols and MAC Classification (~30 min) - Common IoT protocols by layer, MAC protocol taxonomy, protocol selection
  3. Hands-On Configuration (~35 min) - ESP32 configuration, port numbers, troubleshooting, security, bandwidth/latency
  4. Labs and Practice (~45 min) - Interactive labs, Python tools, hands-on exercises

Assessment and Reference:

  1. Assessment Overview (~5 min) - Assessment and reference index
  2. Knowledge Check (~15 min) - 10 self-assessment questions with detailed answers
  3. Reference and Glossary (~10 min) - Comprehensive MCQ quiz, terminology glossary, protocol tables

Estimated total time: 120-150 minutes

2.3.1 Chapter Relationships

Networking chapter relationship diagram showing seven focused chapters organized into core learning (Introduction, Protocols, Hands-On, Labs) and assessment sections (Assessment Overview, Knowledge Check, Reference and Glossary)
Figure 2.1

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:

IoT protocol stack diagram mapping application protocols (MQTT, CoAP, HTTP) to transport layer (TCP, UDP), network layer (IPv6, 6LoWPAN), and physical/MAC layer (Wi-Fi, Zigbee, LoRaWAN, Bluetooth)
Figure 2.2

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:

Quiz: IPv6 and IoT Address Space

Quiz: CSMA vs TDMA MAC Protocols

Quiz: ESP32 Wi-Fi Troubleshooting

Quiz: IoT Security Priority

Quiz: Bandwidth vs Throughput


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:

  1. Bandwidth ≠ Throughput: Expect 30-50% of theoretical bandwidth in typical IoT deployments
  2. Account for all layers: Application goodput requires 40-60% more throughput than payload suggests
  3. Plan for worst-case: Use RSSI -75 dBm, not -50 dBm, for link budget calculations
  4. 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.

Try It: Wi-Fi Goodput Estimator

Adjust the parameters below to see how theoretical bandwidth translates to actual application-layer goodput.

2.9 Practice Quizzes

Match: IoT Protocol and Technology Concepts

Order: Troubleshooting an ESP32 Wi-Fi Connection Failure

Place the following troubleshooting steps in the correct bottom-up sequence when an ESP32 cannot reach its MQTT broker.


Common Pitfalls

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.

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.

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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