27  Layered Network Models

In 60 Seconds

Layered network models divide networking into independent layers – the OSI model uses 7 layers for theoretical clarity while TCP/IP uses 4 for practical implementation. Each layer (Physical, Data Link, Network, Transport, Session, Presentation, Application) handles one specific function, enabling interoperability between billions of diverse devices. For IoT, these models explain how a sensor reading gets packaged with addresses and error-checking at each layer before transmission.

27.1 Overview

Layered network models are the foundation of all network communication, dividing complex networking tasks into manageable, independent layers. This section covers the theoretical OSI model, the practical TCP/IP model, addressing schemes, and hands-on implementation.

OSI 7-layer reference model showing from bottom to top: Physical, Data Link, Network, Transport, Session, Presentation, and Application layers with functions of each layer
Figure 27.1: OSI 7-layer reference model

27.2 Learning Objectives

By the end of this section, you will be able to:

  • Explain Network Standards: Analyze why standards and protocols enable global connectivity across billions of devices
  • Compare OSI and TCP/IP Models: Differentiate between the seven-layer OSI and four-layer TCP/IP models and map layers between them
  • Explain Encapsulation: Describe how data moves through protocol layers and calculate per-layer overhead
  • Apply IoT Reference Models: Evaluate IoT-specific architectural frameworks and select the appropriate model for a given deployment
  • Configure MAC and IP Addressing: Construct and interpret hardware and network layer addresses for IoT devices
  • Implement IPv4/IPv6: Configure and troubleshoot both IP versions in IoT network scenarios
  • Resolve Addresses: Demonstrate how ARP maps MAC addresses to IP addresses and predict ARP behavior in network segments

Network communication is organized in layers, much like a postal system. One layer handles the physical delivery truck, another handles sorting by zip code, and another handles writing the letter itself. Each layer does its own job and passes information to the next, making complex communication manageable and predictable.

“I have a question,” said Sammy the Sensor. “Why can’t I just shout my data straight to the cloud? Why do we need all these layers?”

Max the Microcontroller laughed. “Imagine if everyone in a city tried to deliver their own mail by hand – total chaos! Layers divide the work so each part only worries about its own job. The OSI model has 7 layers for teaching, and TCP/IP has 4 layers for the real internet.”

“Think of it this way,” added Lila the LED. “I do not need to know HOW the Wi-Fi radio works to display information. And Sammy does not need to understand IP addresses to measure temperature. Each of us handles our own layer, and the system just works!”

Bella the Battery chimed in, “Plus, layers save energy! When engineers designed Zigbee, they only had to optimize the bottom layers for low power. The application layer stayed the same. Without layers, they would have had to redesign EVERYTHING. Layers make the whole IoT world possible – billions of different devices all communicating because they agree on the same layered rules.”


27.3 Chapter Contents

This topic is covered in three focused chapters:

27.3.1 1. Layered Models Fundamentals

Core concepts of layered networking – Why standards matter, OSI 7-layer model, TCP/IP 4-layer model, protocol data units (PDUs), encapsulation/decapsulation processes, and IoT reference models.

Topics covered:

  • Networking standards and interoperability
  • OSI 7-layer model (theoretical framework)
  • TCP/IP 4-layer model (practical implementation)
  • Protocol data units at each layer
  • Encapsulation and decapsulation
  • IoT reference models (Cisco 7-Level, ITU)
  • Layer-by-layer troubleshooting

27.3.2 2. Addressing and Implementation

Hands-on addressing and configuration – MAC addressing, IPv4/IPv6 addressing, subnet masks, ARP protocol, and practical labs for configuring network addresses.

Topics covered:

  • MAC address structure and types
  • IPv4 addressing and subnet masks
  • IPv6 addressing and benefits for IoT
  • Address Resolution Protocol (ARP)
  • Hands-on configuration labs
  • Python implementation examples

27.3.3 3. Review and Knowledge Checks

Comprehensive review and assessment – Knowledge checks, quiz questions, worked examples, and visual reference galleries to reinforce understanding.

Topics covered:

  • Key concepts summary
  • Scenario-based knowledge checks
  • Protocol stack selection worked example
  • Visual reference gallery
  • Further learning resources

27.4 Quick Reference

Minimum Viable Understanding

The OSI model (7 layers) is a theoretical framework used for teaching and troubleshooting. The TCP/IP model (4 layers) is the practical implementation that powers the internet. Both use encapsulation – wrapping data in headers as it moves down the stack – and decapsulation – unwrapping headers as it moves up.

Key mapping: TCP/IP Application = OSI Layers 5-7, TCP/IP Transport = OSI Layer 4, TCP/IP Internet = OSI Layer 3, TCP/IP Network Access = OSI Layers 1-2.

Layer Type Addressing Scope
Data Link (L2) MAC addresses (48-bit) Local network segment
Network (L3) IP addresses (IPv4: 32-bit, IPv6: 128-bit) End-to-end routing


27.5 Prerequisites

Before diving into this section, you should be familiar with:


27.6 Knowledge Check

Scenario: A temperature sensor sends readings to a cloud broker via MQTT over Wi-Fi. Map each protocol component to its OSI layer.

Given:

  • Device: ESP32 with temperature sensor
  • Protocol: MQTT over TCP over IP over Wi-Fi
  • Data: {"temp": 23.5, "unit": "C", "timestamp": 1706800000}

Layer-by-Layer Mapping:

OSI Layer Protocol/Component Function in This System
L7 Application MQTT Publishes sensor reading to topic sensors/temp/room1
L6 Presentation JSON encoding Converts temperature struct to {"temp": 23.5, ...} string
L5 Session MQTT keep-alive Maintains persistent connection to broker
L4 Transport TCP Ensures reliable delivery with ACKs, port 1883
L3 Network IPv4 Routes packet from 10.0.1.15 (sensor) to 54.23.1.100 (broker)
L2 Data Link Wi-Fi 802.11 Frames packet for wireless transmission, adds MAC addresses
L1 Physical 2.4 GHz radio Transmits bits as electromagnetic waves

Data Encapsulation (top-down):

  1. Application: MQTT PUBLISH message with topic and payload (40 bytes)
  2. Presentation: JSON string (no additional header, part of payload)
  3. Session: (Managed within MQTT keep-alive packets)
  4. Transport: TCP header added (20 bytes) – segment = 60 bytes
  5. Network: IP header added (20 bytes) – packet = 80 bytes
  6. Data Link: Wi-Fi frame header + trailer (34 bytes) – frame = 114 bytes
  7. Physical: Frame converted to radio signal bits

Total Overhead: 74 bytes of headers for 40 bytes of application data = 185% overhead

\(\text{Payload Efficiency} = \frac{\text{Payload}}{\text{Payload + Overhead}} = \frac{40}{40 + 74} = 35.1\%\)

Key Insight: Each layer adds value (reliability, routing, framing) but also overhead. For constrained IoT devices, protocols like CoAP over UDP reduce overhead by eliminating TCP and using binary encoding instead of JSON.

Try It: IoT Protocol Overhead Calculator

Explore how different protocol stacks affect payload efficiency, daily data usage, and cellular costs for IoT deployments.

Common Pitfalls

A network switch operates at Layer 2 and never inspects IP addresses. A router operates at Layer 3 and does not maintain TCP state. Fix: for each network device type, identify the highest layer it operates at.

The Data Link layer has two sublayers: LLC (Logical Link Control, handles flow control and multiplexing) and MAC (Medium Access Control, handles channel access). Wi-Fi and Ethernet differ at the MAC sublayer but share the LLC sublayer. Fix: distinguish LLC from MAC when comparing wireless and wired Data Link protocols.

In IoT, 6LoWPAN adapts IPv6 at a sublayer between the MAC and Network layers, and some IoT stacks omit the Network layer entirely for short-range communication. Fix: always verify which layers are present in a specific IoT protocol stack rather than assuming standard TCP/IP applies.

27.7 What’s Next

After completing these chapters, continue with the following related topics:

Topic Chapter Description
Routing Fundamentals Routing Fundamentals How packets find their way across networks using routing tables, algorithms, and protocols like RPL
Transport Protocols Transport Protocols Compare TCP reliable delivery vs UDP lightweight transfer and when to use each for IoT
Network Mechanisms Network Mechanisms Packet switching, datagrams, and how IoT data traverses multi-hop networks
IoT Protocols IoT Protocols Fundamentals Application-layer protocols (MQTT, CoAP, AMQP) built on top of the layered stack
Network Topologies Network Topologies Star, mesh, and tree topologies and how they interact with addressing and routing
MAC Addressing Addressing and Implementation Hands-on labs for configuring MAC and IP addresses on real IoT devices