OSI Model vs TCP/IP Model: Layers and Encapsulation

Networking is split into layers so that each one can change without the others noticing: the same web request travels over Wi-Fi, Ethernet or a mobile link without the browser knowing which. The OSI model describes seven layers; the TCP/IP model that the internet actually runs on uses four. This page lines them up, then follows one HTTP request down the stack, header by header, and lets tcpdump decode the result.

Learning objectives

  • Name the seven OSI layers and the four TCP/IP layers, and map one onto the other
  • Say which layer a protocol or device belongs to
  • Explain encapsulation: what each layer adds and why
  • Compute header overhead, efficiency and IP fragments
  • Compute and check an Internet checksum

Prerequisites

  • Bytes and hexadecimal
  • Nothing else: every header is shown byte by byte

The two models side by side

OSI layerWhat it doesTCP/IP layerExamples
7 Applicationthe program's own protocolApplicationHTTP, DNS, SMTP
6 Presentationencoding, compression, encryptionApplicationTLS, character sets
5 Sessionopening and closing conversationsApplicationhandled by the application
4 Transportend-to-end delivery between programs (ports)TransportTCP, UDP
3 Networkaddressing and routing between networksInternetIPv4, IPv6, ICMP
2 Data linkframes between neighbors on one linkLinkEthernet, Wi-Fi MAC
1 Physicalbits as signals on a wire or radioLinkEthernet PHY, cables

Why two models

The OSI model came first, as a reference for designing protocols; the TCP/IP model describes the protocols that won. TCP/IP folds OSI's layers 5 to 7 into one application layer, because applications handle sessions and encoding themselves, and folds layers 1 and 2 into one link layer. The OSI numbers are still how engineers talk: a layer 2 switch forwards Ethernet frames by MAC address, a layer 3 router forwards IP packets by IP address.

Encapsulation

On the way down, each layer treats whatever the layer above hands it as opaque data and puts its own header in front. TCP adds ports and sequence numbers, IP adds source and destination addresses, Ethernet adds MAC addresses in front and a checksum, the frame check sequence, behind. On the way up, each layer strips its own header and passes the rest up. Each header is read only by the same layer at the other end.

An HTTP request wrapped in TCP, IP and Ethernet headers, with the size of each part in bytes
A 37-byte HTTP request gains a TCP header, an IP header, and an Ethernet header and trailer on its way down.

Worked example: one request, every byte

Follow the frame for a 37-byte HTTP request, from the inside out. Addresses come from the documentation ranges, so they belong to no real host. Both checksums are the Internet checksum, a one's complement sum of 16-bit words; TCP's also covers a pseudo-header of the IP addresses, so a segment delivered to the wrong host fails it.

LayerAddsSizeChecksum
Application (HTTP request)37 bytes
TCP segment20-byte header57 bytes0xa2ef
IPv4 packet20-byte header77 bytes0x3213
Ethernet frame14-byte header, 4-byte FCS95 bytesFCS 0x5e0e4d44
On the wire8-byte preamble, 12-byte gap115 byte times32.2% carries the request

Each header with its checksum in place sums to zero, and the frame's CRC-32 leaves the fixed residue. The IPv4 header is 45 00 00 4d 1c 46 40 00 40 06 32 13 c0 00 02 0a c6 33 64 14, and the TCP header c0 00 00 50 00 00 03 e8 00 00 13 88 50 18 ff ff a2 ef 00 00. Written to a capture file, the frame decodes cleanly in tcpdump, which parses every layer and confirms the TCP checksum.

tcpdump -nn -vv -r frame.pcap
IP (tos 0x0, ttl 64, id 7238, offset 0, flags [DF], proto TCP (6), length 77)
   192.0.2.10.49152 > 198.51.100.20.80: Flags [P.], cksum 0xa2ef (correct), seq 1000:1037, ack 5000, win 65535, length 37: HTTP, length: 37
	GET / HTTP/1.1
	Host: example.com

Only 32 percent of the time on the wire carried the request; the rest is headers, the frame check sequence, the preamble and the gap between frames. A full-size frame with 1460 bytes of data reaches 95 percent, which is why 1 Gb/s Ethernet moves at most about 949 Mb/s of TCP data.

Share of Ethernet wire time carrying TCP data, rising with the data bytes per frame
The share of the wire that carries data grows with the payload: 32 percent for the 37-byte request, 95 percent for a full frame.

Common mistakes

  • Treating the models as protocols. They are descriptions; TCP/IP is the one implemented.
  • Putting TLS at the transport layer because it runs over TCP. It encrypts application data and sits above TCP.
  • Forgetting the preamble and interframe gap when computing Ethernet throughput.
  • Calling a router a layer 2 device. Routers forward by IP address, layer 3; switches forward by MAC address, layer 2.
  • Computing the IP checksum over the payload too. IPv4's covers the header only; TCP's covers its header, data and the pseudo-header.

Quick check

1. Which TCP/IP layer covers OSI layers 5, 6 and 7?

The application layer.

2. A switch forwards frames by MAC address. Which OSI layer is it?

Layer 2, data link.

3. Which header holds the port numbers?

The transport header: TCP or UDP.

Exercises

E1 (easy). How much of the wire carries data when TCP sends 100 bytes, and when it sends 1 byte?

100 bytes: a 140-byte IP packet, 178 byte times on the wire, 56.2 percent. 1 byte: the 41-byte packet is padded to Ethernet's 46-byte minimum, 84 byte times, 1.2 percent.

E2 (medium). A 4000-byte IPv4 datagram (20-byte header) crosses a link with a 1500-byte MTU. Give each fragment's size, offset field and more-fragments flag.

Each fragment carries at most 1480 data bytes, a multiple of 8. Fragments of 1500, 1500 and 1040 bytes, with offset fields 0, 185 and 370 (in 8-byte units) and the more-fragments flag set on all but the last.

E3 (medium). Compute the header checksum of 45 00 00 3c ab cd 00 00 80 11 [00 00] c0 00 02 01 c6 33 64 07.

Add the ten 16-bit words with the checksum field as zero, fold the carries back in, and take the one's complement: 0xa2a7. With it in place, the header sums to zero.

E4 (hard). What is the most TCP data 1 Gb/s Ethernet can carry, without and with the 12-byte TCP timestamps option?

Each 1500-byte IP packet takes 1538 byte times on the wire. With 1460 data bytes that is 949.3 Mb/s; the timestamps option leaves 1448 bytes, 941.5 Mb/s.

Interview questions

  • Q1. What happens, layer by layer, when you load a web page? Answer: DNS resolves the name; TCP (and TLS) set up a connection to port 443; HTTP sends the request; IP routes each packet hop by hop; at each hop the link layer delivers frames by MAC address, found with ARP.
  • Q2. Why does TCP's checksum include a pseudo-header? Answer: to catch a segment delivered to the wrong host or protocol, since the IP addresses and protocol number are covered too.
  • Q3. What is the difference between TCP and UDP? Answer: TCP gives reliable, ordered delivery with connection setup and flow control; UDP sends independent datagrams with no delivery guarantee and less overhead.

Summary

  • OSI has seven layers; TCP/IP has four, merging 5 to 7 and 1 to 2.
  • Each layer adds its header on the way down and removes it on the way up.
  • TCP adds ports, IP adds addresses, Ethernet adds MAC addresses and a frame check sequence.
  • Headers cost: 32 percent useful for a small request, 95 percent for a full frame.

Related

Sources

Last verified

Checked with tcpdump on 27 November 2026; the header layouts follow RFC 791 and RFC 9293.