Layered Models: OSI and TCP/IP

A computer network is extraordinarily complex: radio waves, copper electrons, fibre photons, routers, switches, operating systems, and web servers all need to work together. The only way to manage this complexity is modular design through layering. Each layer provides a well-defined service to the layer above it and depends only on the service offered by the layer below. Internal implementation details are hidden — a change inside one layer (e.g. upgrading from copper to fibre) doesn't require changes in other layers.

This idea gave rise to two reference models that you'll encounter everywhere: OSI (a theoretical framework from ISO) and TCP/IP (the practical model the internet actually uses).

The OSI model (7 layers)

The Open Systems Interconnection model (ISO/IEC 7498-1) was published in 1984 as a vendor-neutral reference framework intended to allow different manufacturers' systems to interoperate. It was never widely implemented as a complete protocol suite, but its layer terminology is still universally used for diagnosis and discussion.

#LayerRoleExample protocols / techDevice that operates here
7ApplicationUser-facing network servicesHTTP, DNS, SMTP, FTP, SNMPApplication software
6Presentation Not on examData representation, serialisation, encryption, compressionTLS/SSL (encryption), JPEG, ASN.1, XDRApplication / TLS library
5Session Not on examEstablishing, managing, and terminating sessions between applicationsRPC, NetBIOS, SIP (partly)Application / middleware
4TransportEnd-to-end communication, reliability, multiplexingTCP, UDP, SCTP, QUICOS kernel, host
3NetworkLogical addressing, routing between networksIPv4, IPv6, ICMP, OSPF, BGPRouter, layer-3 switch
2Data LinkNode-to-node framing, MAC addressing, error detection on one linkEthernet (802.3), Wi-Fi (802.11), PPP, ARPSwitch, bridge, NIC
1PhysicalRaw bit transmission over a physical mediumCopper (Cat6), fibre (SMF/MMF), radio (802.11), DSLHub, repeater, NIC hardware

Exam note: The OSI model is only a theoretical model (on a "nice-to-know" level), and the exam will NOT ask questions about the Presentation (Layer 6) or Session (Layer 5) layers. The TCP/IP model is used in practice.

A useful mnemonic for layers 7→1: "All People Seem To Need Data Processing". For 1→7: "Please Do Not Throw Sausage Pizza Away."

The TCP/IP model (4 layers) and the 5-layer Internet model

The original TCP/IP model (RFC 1122), derived from ARPANET design documents, describes the internet's protocol stack in 4 layers. It merges OSI's top three layers into one Application layer, and merges the Data Link and Physical layers into a single Link (or Network Access) layer. However, computer networking textbooks (such as Kurose & Ross or Tanenbaum) and university exams frequently teach a 5-layer model that splits the bottom layer into separate Link and Physical layers, providing a clearer distinction between framing/addressing and physical bit transmission.

4-Layer TCP/IP5-Layer Internet ModelCorresponds to OSIKey protocols & hardwarePDU name
Application5. Application7 + 6 + 5 (App, Pres, Sess)HTTP/2/3, DNS, SMTP, SSH, TLS, DHCPMessage / Data
Transport4. Transport4 (Transport)TCP, UDP, QUIC, SCTPSegment / Datagram
Internet3. Network (Internet)3 (Network)IPv4, IPv6, ICMP, ICMPv6, ARP*Packet
Link (Network Access)2. Data Link2 (Data Link)Ethernet (802.3), Wi-Fi (802.11), PPP, switchesFrame
(Physical merged into Link)1. Physical1 (Physical)1000BASE-T copper, single/multi-mode fibre, radio RF, hubsBits / Symbols

* Note: ARP is technically link-layer (operates over local broadcast domains) but is often grouped with the Internet/Network layer because it directly resolves addresses for IP. Textbooks and academic courses overwhelmingly adopt the 5-layer model because isolating physical transmission properties (cables, modulation) from framing algorithms is essential for conceptual clarity.

Nice-to-know: Why TCP/IP won in practice while OSI remained theoretical

During the early 1980s, the International Organization for Standardization (ISO) spent years defining the formal 7-layer Open Systems Interconnection (OSI) protocol suite through exhaustive international committee negotiations. Meanwhile, the simpler TCP/IP protocols were already running on the ARPANET and were bundled free of charge into BSD Unix (4.2BSD, 1983).

Universities, researchers, and early internet engineers rapidly adopted the freely available, battle-tested TCP/IP code, embracing the Internet Engineering Task Force (IETF)'s famous pragmatic philosophy: "We reject: kings, presidents and voting. We believe in: rough consensus and running code."

Architecturally, OSI's Layer 5 (Session) and Layer 6 (Presentation) proved largely redundant as operating system services. In modern software engineering, session tracking (such as cookies and auth tokens) and presentation responsibilities (such as JSON, UTF-8 text encoding, MIME formatting, and TLS cryptographic handshakes) are implemented directly inside application processes and user-space libraries rather than kernel network drivers. Today, we use OSI layer numbering (Layers 1–4 and Layer 7) as our shared vocabulary, while running the pragmatic TCP/IP protocol stack in practice.

Why layers matter: the service model

Each layer provides a service to the layer above via a well-defined interface, and uses the service of the layer below. For example:

  • The Transport layer asks the Internet layer: "Deliver this segment to 203.0.113.10 (illustrative address)." It doesn't care whether the path uses Ethernet, Wi-Fi, or a 4G radio link.
  • The Application layer asks the Transport layer: "Give me a reliable byte stream to port 443." It doesn't care about sequence numbers or retransmissions.

This abstraction is what allowed HTTP, which was designed in 1991, to run over HTTP/3+QUIC in 2022 without any changes to what HTTP means — only the layers underneath changed.

Encapsulation and decapsulation — in detail

When data travels down the stack at the sender, each layer wraps the payload from the layer above with its own header (and sometimes a trailer). This is encapsulation. At the receiver, each layer peels off its header — decapsulation.

The PDU names at each layer:

  • Application → produces data (e.g. an HTTP message)
  • Transport → adds TCP/UDP header → segment (TCP) or datagram (UDP)
  • Internet → adds IP header → packet
  • Link → adds Ethernet header + FCS trailer → frame
  • Physical → encodes as electrical/optical/radio signals → bits

How decapsulation knows which upper-layer protocol to call

When an incoming frame arrives at a network interface card (NIC), the receiving operating system must determine which software protocol handler should process the inner payload at each step up the stack. Every layer solves this by embedding a standardised demultiplexing key (a type/protocol identifier field) inside its header:

LayerDemultiplexing header fieldKey valuesTarget protocol / handler
Layer 2 (Data Link) EtherType (16 bits in Ethernet header) 0x0800
0x86DD
0x0806
IPv4 protocol module
IPv6 protocol module
ARP module
Layer 3 (Network) Protocol (8 bits in IPv4)
Next Header (8 bits in IPv6)
6
17
1 (IPv4) / 58 (IPv6)
TCP protocol module
UDP protocol module
ICMP kernel handler
Layer 4 (Transport) Destination Port (16 bits in TCP/UDP) 443
53
22
HTTPS web server process socket
DNS resolver process socket
SSH daemon (sshd) socket
HTTP message Application Data TCP hdr HTTP message Transport Segment IP hdr TCP segment Internet Packet Eth hdr IP packet FCS Frame 20+ bytes 20+ bytes 14 bytes 4 bytes
Encapsulation: each layer prepends a header. The link layer also appends an FCS trailer. Header sizes shown are minimums.

Note that an Ethernet frame carrying a minimum-sized TCP segment over IPv4 has:

Ethernet header (14 B) + IP header (20 B) + TCP header (20 B) + data + FCS (4 B)
= 58 bytes of overhead before any application data even begins

On the wire, each transmitted frame also costs an 8-byte Preamble + Start Frame Delimiter (SFD) for receiver clock synchronization, as well as a minimum 12-byte Inter-Frame Gap (IFG) of idle silence. Therefore, raw wire capacity and transmission-line calculations should add 20 bytes of physical-layer overhead per frame to the link-layer size.

Worked calculation — Protocol Efficiency and Goodput on 1 Gbps Ethernet:

1. Application payload per frame (MSS) : 1,500 (MTU) − 20 (IP) − 20 (TCP) = 1,460 bytes
2. Total link-layer frame size         : 1,460 (data) + 20 (TCP) + 20 (IP) + 14 (Eth) + 4 (FCS) = 1,518 bytes
3. Total bytes consumed on physical wire: 1,518 (frame) + 7 (Preamble) + 1 (SFD) + 12 (IFG) = 1,538 bytes
4. Wire protocol efficiency             : 1,460 ÷ 1,538 ≈ 0.949285 (94.93%)
5. Theoretical max goodput at 1 Gbps    : 1,000 Mbps × 0.949285 ≈ 949.3 Mbps

This 94.93% wire efficiency explains why an internet speed test on a 1 Gbps Gigabit Ethernet cable tops out around 940–949 Mbps, never reaching the full 1,000 Mbps link rate. Even when the physical cable is 100% saturated with data, the missing ~51–60 Mbps is fundamentally consumed by Ethernet headers, IP headers, TCP acknowledgements, and physical line framing.

Note that application-layer header compression schemes like HPACK (HTTP/2) and QPACK (HTTP/3) compress HTTP headers only, not the underlying Ethernet, IP, or TCP headers. Fixed lower-layer overhead matters most for small packets (such as TCP ACKs, DNS queries, or VoIP audio frames), where 58 bytes of headers can easily exceed the payload itself. In bandwidth-constrained environments, header compression for lower layers does exist — such as ROHC (Robust Header Compression, RFC 3095/5795) on cellular networks and 6LoWPAN (RFC 6282) in IoT sensor networks, which compress 40-byte IPv6/UDP headers down to just 2 to 4 bytes.

Peer-to-peer communication: the illusion of direct dialogue

Although data physically moves down the sender's stack, across the wire, and up the receiver's stack, each layer logically communicates with the same layer on the remote machine. The TCP layer on your laptop sends a segment that the TCP layer on the server receives — the IP and Ethernet layers are transparent to TCP. This is why we say layers communicate with their peers.

This separation creates a fundamental distinction between end-to-end layers and hop-by-hop layers across intermediate network devices:

  • End hosts (Host A & Host B): Implement the full 5-layer stack (Physical up to Application). The Transport layer (Layer 4) and Application layer (Layer 5/7) are strictly end-to-end: their headers are generated by Host A and inspected only by Host B. Intermediate networking devices do not modify or terminate them.
  • Link-layer Switch (Layer 2 device): Operates only through Layers 1 and 2. A switch receives physical bits (Layer 1), verifies the Ethernet FCS trailer and inspects the 6-byte destination MAC address (Layer 2), and forwards the exact same frame out the appropriate switch port. The switch never modifies MAC addresses or inspects the inner IP packet.
  • Router (Layer 3 device): Operates through Layers 1, 2, and 3. A router receives incoming bits (Layer 1), validates and completely discards the incoming Layer 2 Ethernet header and FCS (Layer 2), inspects the destination IP address in the routing table, and decrements the IP TTL counter (Layer 3). It then encapsulates the IP packet inside a brand-new Layer 2 frame with new source and destination MAC addresses tailored for the next hop link.
Host A (Source) L2 Switch L3 Router Host B (Dest) 5. Application 4. Transport 3. Network 2. Data Link 1. Physical 2. Data Link 1. Physical 3. Network 2. Data Link 1. Physical 5. Application 4. Transport 3. Network 2. Data Link 1. Physical End-to-End Application Message (HTTP) End-to-End Transport Connection (TCP) Checks MAC & FCS (Frame unchanged) Routes IP, decrements TTL (Rewrites L2 MAC frame) Encapsulates Decapsulates
Hop-by-hop packet traversal: Layer 2 switches inspect only L1/L2; Layer 3 routers strip and replace L2 frames while routing at L3; end hosts execute the full 5-layer stack.

Where TLS fits in practice

TLS technically sits between the Application and Transport layers — it's what OSI would call the Presentation layer. In the TCP/IP model it's simply part of the Application layer from a conceptual standpoint, but it's implemented as a library that wraps the TCP socket. Understanding this explains why TLS handles encryption but TCP still handles retransmission and ordering.

Interactive: click a layer to see its header

Encapsulation visualiser — click a layer to expand

Key takeaways

  • OSI has 7 layers (mnemonic: "All People Seem To Need Data Processing"); TCP/IP collapses them to 4 practical layers.
  • Each layer provides a service to the layer above via an interface, hiding implementation details.
  • PDU names: Data → Segment → Packet → Frame → Bits (top to bottom).
  • Encapsulation adds headers going down the stack; decapsulation strips them going up.
  • Overhead per frame on Ethernet+IPv4+TCP is at least 58 bytes before any application data.
  • TLS sits between Application and Transport; it's the "Presentation layer" of the TCP/IP world.

Quick check — Chapter 1

1. What is the PDU (Protocol Data Unit) name at the TCP/IP Transport layer (TCP)?

TCP's PDU is called a segment. UDP's PDU is a datagram. "Packet" is the IP-layer PDU; "frame" is the link-layer PDU.

2. At which OSI layer does a router primarily operate?

Routers operate at Layer 3 (Network). They read IP addresses and make forwarding decisions based on routing tables. Switches primarily operate at Layer 2 (MAC addresses); hubs at Layer 1.

3. What is the minimum total header overhead (bytes) added to application data in an Ethernet + IPv4 + TCP frame (no IP or TCP options), excluding the FCS trailer?

Ethernet header (destination MAC 6 B + source MAC 6 B + EtherType 2 B) = 14 bytes. IPv4 header (no options) = 20 bytes. TCP header (no options) = 20 bytes.
Minimum header overhead = 14 + 20 + 20 = 54 bytes excluding FCS. Including the 4-byte Ethernet Frame Check Sequence (FCS) trailer, the total overhead is 58 bytes. Because this question specifically excludes the FCS trailer, the correct answer is 54 bytes.

4. Which process strips headers as data travels up the receiving stack?

Decapsulation happens at the receiver: as data travels up the stack, each layer strips its own header (and any trailer), exposing the next layer's PDU to the layer above.

5. A TCP segment carries 100 bytes of application data in an Ethernet frame with no IP or TCP options. What fraction of the transmitted Ethernet frame (including the 4-byte FCS) is header/trailer overhead?

Total overhead = 14 B (Ethernet header) + 20 B (IPv4 header) + 20 B (TCP header) + 4 B (Ethernet FCS trailer) = 58 bytes.
Total frame size = 58 bytes overhead + 100 bytes data = 158 bytes.
Overhead fraction = 58 ÷ 158 ≈ 0.3671 = about 36.7%.

6. When an HTTP/TCP/IPv4 packet travels from a laptop through an Ethernet switch and an IP router to a web server, which layers of the protocol stack are inspected and modified by the IP router?

An IP router is a Layer 3 device: it receives physical bits (Layer 1), verifies and strips the incoming Ethernet frame (Layer 2), inspects the IP packet header and decrements the TTL (Layer 3), and re-encapsulates the packet in a brand-new Layer 2 frame with new MAC addresses. Transport (Layer 4) and Application (Layer 5/7) headers are end-to-end and are never modified by intermediate routers.

7. A full-sized Ethernet frame carries 1,460 bytes of TCP application data (MSS). Including the 14B Ethernet header, 20B IPv4 header, 20B TCP header, 4B FCS trailer, and 20B of physical wire overhead (Preamble + SFD + Inter-Frame Gap), what is the total wire size per frame and the resulting maximum application goodput on a 100 Mbps link?

Total wire size = 1,460 (MSS data) + 20 (TCP) + 20 (IP) + 14 (Ethernet) + 4 (FCS) + 20 (Preamble + SFD + IFG) = 1,538 bytes.
Protocol efficiency = 1,460 ÷ 1,538 ≈ 0.949285 (94.93%).
Maximum goodput on a 100 Mbps link = 100 Mbps × 0.949285 = ~94.9 Mbps.