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 layer | What it does | TCP/IP layer | Examples |
|---|---|---|---|
| 7 Application | the program's own protocol | Application | HTTP, DNS, SMTP |
| 6 Presentation | encoding, compression, encryption | Application | TLS, character sets |
| 5 Session | opening and closing conversations | Application | handled by the application |
| 4 Transport | end-to-end delivery between programs (ports) | Transport | TCP, UDP |
| 3 Network | addressing and routing between networks | Internet | IPv4, IPv6, ICMP |
| 2 Data link | frames between neighbors on one link | Link | Ethernet, Wi-Fi MAC |
| 1 Physical | bits as signals on a wire or radio | Link | Ethernet 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.
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.
| Layer | Adds | Size | Checksum |
|---|---|---|---|
| Application (HTTP request) | 37 bytes | ||
| TCP segment | 20-byte header | 57 bytes | 0xa2ef |
| IPv4 packet | 20-byte header | 77 bytes | 0x3213 |
| Ethernet frame | 14-byte header, 4-byte FCS | 95 bytes | FCS 0x5e0e4d44 |
| On the wire | 8-byte preamble, 12-byte gap | 115 byte times | 32.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.
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.comOnly 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.
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
- ITU-T X.200: the OSI basic reference model
- RFC 1122: requirements for Internet hosts, communication layers
- RFC 791: Internet Protocol (IPv4)
- RFC 9293: Transmission Control Protocol (TCP)
- RFC 1071: computing the Internet checksum
- RFC 894: IP datagrams over Ethernet
- RFC 5737: IPv4 address blocks reserved for documentation
Last verified
Checked with tcpdump on 27 November 2026; the header layouts follow RFC 791 and RFC 9293.