Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 1 of 6 · Concept · 20 min · revision 1

Layers that matter in practice: OSI vs TCP/IP and encapsulation

Map protocols and devices to the TCP/IP and OSI layers, predict which header fields change at a switch, a router and a NAT, and work out header overhead, MSS and Path MTU Discovery from what a capture shows.

Contentsand lesson path

What you will learn

  • Map protocols and devices to OSI and TCP/IP layers and explain encapsulation, header overhead and MTU using a real capture.

Prerequisites: Networking Basics

01. Why it matters

Suppose a colleague hands you a capture taken on a web server and asks two questions. First: "Every request in this file arrives from the MAC address of our own router, not from the customers' laptops. Is the router impersonating them?" Second: "The link MTU is 1,500 bytes, yet no data segment carries more than 1,448 bytes of payload. Are we wasting capacity?"

ping, curl -v and the application log cannot answer either question, because they report what the endpoints decided, not what crossed the wire. Both answers come from one idea: each layer wraps the data from the layer above in its own header, some headers are rewritten at every hop, and every header byte comes out of a fixed budget.

02. From tool output to the two layer models

The first tools engineers reach for are good ones: ss shows socket states, curl -v the TLS and HTTP exchange, the server log the request. When an endpoint reports the failure (a refused connection, a DNS error, an expired certificate), they name the cause and a capture adds little. They fall short when something between the endpoints changes or drops traffic, because each endpoint then sees only a timeout, a stall or an unexplained reset.

To read a capture you need a map of the layers. The Internet is built on the four-layer TCP/IP model, which the debugging map lesson introduced. Engineers still number layers with the seven-layer OSI (Open Systems Interconnection) model, so "a Layer 2 problem" means Ethernet or Wi-Fi framing and "a Layer 7 load balancer" means one that reads HTTP. The diagram lines the two models up and places common devices on them.

Wireshark shows the same stack in its packet details pane, one line per header, outermost first: Frame (capture metadata), Ethernet II, Internet Protocol Version 4, Transmission Control Protocol, then the application protocol. TLS is an edge case: textbooks often put it at OSI layers 5–6, but its records ride inside TCP segments, so the TCP/IP model counts it as application data.

Text · OSI layers, TCP/IP layers and where common devices work
OSI model                  TCP/IP model        Protocols and devices
-------------------------  ------------------  -------------------------------
7 Application   \          Application         HTTP, DNS, SSH, TLS records
6 Presentation   |------->                     (L7 proxies, WAFs)
5 Session       /
4 Transport     ---------> Transport           TCP, UDP, QUIC (L4 balancers)
3 Network       ---------> Internet            IPv4, IPv6, ICMP (routers, NAT)
2 Data Link     \          Link                Ethernet, 802.1Q, Wi-Fi (switches)
1 Physical      /                              Copper, fibre, radio, NICs

03. Encapsulation and what changes at each hop

Every layer adds its own envelope around the data handed down from above, a process called encapsulation. When an application writes an HTTP request, TCP puts a header in front of it (the result is a segment), IP puts its header in front of that (a packet), and Ethernet adds a 14-byte header in front and a 4-byte Frame Check Sequence (FCS) behind (a frame). The FCS is a checksum that lets the next receiver detect damaged frames. The receiving host unwraps the layers in the opposite order.

Devices on the path open different envelopes, and that decides what they change:

  • An Ethernet switch works at Layer 2. It reads the destination MAC (Media Access Control) address, looks it up in its table and forwards the frame out of one port, without rewriting the MACs, the IP header or anything inside.
  • A router works at Layer 3. It removes the incoming Ethernet header and FCS, lowers the IPv4 TTL (Time to Live) or IPv6 Hop Limit by one, recomputes the IPv4 header checksum, chooses the next hop and builds a new frame for the outgoing link, with its own MAC as the source.
  • A NAT gateway (Network Address Translation) is a router that also rewrites IP addresses and usually ports, which forces it to recompute the TCP or UDP checksum as well.

That answers the first question. Frames from another subnet always carry the source MAC of the last router, because a MAC address only means something on one link, while the customers' IP addresses travel end to end unless a NAT replaced them.

Text · One full-size TCP/IPv4 frame: the MTU covers the IP packet only
|   14 B   |   20 B    |   20 B    |      up to 1460 B      |  4 B  |
+----------+-----------+-----------+------------------------+-------+
| Eth hdr  | IPv4 hdr  |  TCP hdr  |    application data    |  FCS  |
+----------+-----------+-----------+------------------------+-------+
           |<------ IP packet: at most 1500 B (MTU) ------->|
|<------------------ Ethernet frame: up to 1518 B ----------------->|

04. Header overhead, MTU and the MSS a capture shows

The Maximum Transmission Unit (MTU) of a link is the largest IP packet, header included, that the link carries without fragmenting it. Standard Ethernet has an MTU of 1,500 bytes, and the Ethernet header and FCS sit outside that number, as the bracket in the diagram shows. Everything inside the packet comes out of the 1,500 bytes:

  • TCP over IPv4: a 20-byte IPv4 header (RFC 791) and a 20-byte TCP header (RFC 9293) leave 1,460 bytes of data.
  • UDP over IPv4: the UDP header is a fixed 8 bytes (RFC 768), leaving 1,472 bytes.
  • TCP over IPv6: the IPv6 header is a fixed 40 bytes (RFC 8200), leaving 1,440 bytes.

For TCP, the hosts tell each other this budget. Each side puts a Maximum Segment Size (MSS) option in its SYN: the largest block of data it is willing to receive in one segment, normally its MTU minus 40 for IPv4, so a handshake on Ethernet shows mss 1460. RFC 9293 (section 3.7.1) tells the sender how to use the value it received: data per segment is the peer's MSS plus 20, minus the TCP header including the options it actually sends. Linux enables TCP timestamps by default (net.ipv4.tcp_timestamps) and sends them on every data segment: 10 bytes, padded to 12 with two no-operation bytes. So 1460 + 20 − 32 = 1,448, which answers the second question: nothing is wasted, the 12 bytes carry timing data that TCP uses to measure round-trip time. When you open a capture, read both MSS values in the handshake; a value below 1460 means a smaller link near that host, or a middlebox rewriting it on purpose.

05. When a packet does not fit: Path MTU Discovery

The MSS exchange only tells each host about the links at the two ends. A tunnel in the middle has a smaller MTU, because it wraps every packet in extra headers: basic GRE, for example, adds a 20-byte outer IPv4 header and a 4-byte GRE header, so a GRE tunnel over a 1,500-byte link carries packets of at most 1,476 bytes.

IPv4 handles this with Path MTU Discovery (PMTUD), described in RFC 1191. The source host starts by assuming the path MTU equals the MTU of its own link and sets the Don't Fragment (DF) bit on its packets. A router that cannot forward such a packet onto a smaller link drops it and returns an ICMP "Destination Unreachable, fragmentation needed and DF set" message (type 3, code 4) that carries the next-hop MTU. The source host lowers its estimate for that destination and resends smaller packets. Routers take no part in the discovery beyond dropping and reporting. In IPv6, routers never fragment at all; they send ICMPv6 Packet Too Big, and the source reacts in the same way (RFC 8201).

The weak point is the ICMP message. If a firewall drops it, the sender never learns the real limit and keeps retransmitting full-size packets that are dropped every time, while exchanges of small packets keep working. This is a PMTUD black hole. The two common repairs are to let the ICMP messages through, or to have the tunnel router lower the MSS in passing SYNs (MSS clamping). Clamping helps only TCP: a UDP application, including QUIC (RFC 9000, section 14), has no MSS and must size its datagrams itself.

What if the host used IPv6? Full-size TCP packets would carry 20 bytes less data (1,440 before options), and since no router may fragment them, Packet Too Big is the only way the source learns about a smaller link.

This level of detail is unnecessary when curl -v against a service on the same subnet fails with Connection refused or an HTTP 500: the problem is in the endpoint. Read layer by layer when tunnels, middleboxes or rewrites can hide the cause from both ends.

06. Check your understanding

Practice check · 3 questions

Headers, hops and packet sizes

Predict what a capture will show. Work out each answer before you look at the options.

Q1. A capture shows the client's SYN with `mss 1460` and the server's SYN-ACK with `mss 1380`. Both sides send 12 bytes of TCP timestamp options on every data segment. How much data does the client put in each full-sized segment it sends?
Q2. Hosts A and B sit on the same VLAN with one Ethernet switch between them. You capture the same ICMP echo request on A's interface and on B's interface. What differs between the two copies?
Q3. During an upload, a capture on the client shows a 1,500-byte IPv4 packet with DF set, then `ICMP ... unreachable - need to frag (mtu 1380)` from a router. The connection uses 12 bytes of TCP timestamp options. What do the client's retransmissions of that data look like?
Practice only: not graded, not saved, not evidence.

07. Apply it

Suppose a monitoring agent sends 1,472-byte UDP datagrams over IPv4 on a 1,500-byte Ethernet link. The link is then moved onto an 802.1Q trunk, and later the traffic is carried through a basic GRE tunnel over that trunk. For each change, work out whether the datagrams still fit without fragmentation, and which layer's header changed the IP budget and which did not. Then describe what a capture would show if the agent sets DF and the ICMP message is blocked.

The skill practice asks you to label each layer's overhead in a real capture. In the next lesson you will build a two-hop network in Linux namespaces, watch MACs and TTLs change at a router, and trigger a real "fragmentation needed" message.

08. Review prompt

Without looking back, explain why a server sees the router's MAC address but the client's IP address, why the Ethernet header and FCS do not count against the 1,500-byte MTU, how a TCP sender turns the peer's advertised MSS into the size of its data segments, and why blocking ICMP "fragmentation needed" messages breaks only the connections that send full-size packets.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check