TCP/IP model & encapsulation
Explain how data is wrapped into segments, packets and frames on the way down the stack.
By Invicly Tech, , in Computer Networking. About 10 minutes to read.
In short
The TCP/IP model has four layers: application, transport, internet and link. As data moves down the stack each layer adds its own header, wrapping the data like nested envelopes, and the receiver unwraps them in reverse. This encapsulation is what you see layer by layer in a Wireshark capture.
Think of it like this: A letter goes in an envelope, the envelope in a mailbag, the mailbag in a truck; each handler only reads its own label.
Explained simply
The TCP/IP model is the one the internet really uses. It has four layers instead of seven: application, transport, internet and link. The top three OSI layers fold into application, and the bottom two fold into link.
When you send data, it travels down the layers. Each layer wraps what it got from above in its own header, like putting a letter in an envelope, then that envelope in a bigger one. When the data arrives, the receiver opens the envelopes in reverse order. This wrapping is called encapsulation.
Each wrapped unit has a name. TCP makes segments, UDP makes datagrams, IP makes packets, and Ethernet makes frames. Knowing the names helps you read tools like Wireshark and talk clearly with other engineers.
Every header costs bytes. A normal Ethernet frame can carry 1500 bytes of payload, called the MTU. IP and TCP headers take at least 40 of those bytes, so a full packet carries at most 1460 bytes of your actual data. When tunnels add more headers, the space for data shrinks further.
Press Play on a diagram to walk through it one step at a time.
- 1Application data
GET /index.html
- 2TCP segment
+ TCP header: ports, sequence numbers
- 3IP packet
+ IP header: source and destination IP
- 4Ethernet frame
+ MAC header and FCS trailer
- 5Bits
Signals on copper, fibre or radio
- 1Preamble + SFD
8 bytes, before the frame
- 2Ethernet header
14 bytes: MACs and EtherType
- 3IPv4 header
20 bytes
- 4TCP header
20 bytes (32 with timestamps)
- 5Your data
1460 bytes (1448 with timestamps)
- 6FCS + interframe gap
4 + 12 bytes
In depth
TCP/IP layers next to OSI
The TCP/IP model, described in RFC 1122, has four layers. The application layer covers OSI layers 5, 6 and 7: HTTP, DNS, TLS and SSH all live here, and each app handles its own sessions and encoding. The transport layer matches OSI layer 4: TCP and UDP, with port numbers. The internet layer matches OSI layer 3: IPv4, IPv6 and ICMP. The link layer covers OSI layers 1 and 2: Ethernet, Wi-Fi and the physical signals.
Some textbooks show a five-layer hybrid that splits link into data link and physical. It is the same idea, just with the hardware layer named separately. Whichever version you use, the numbers engineers say out loud (layer 2, layer 3, layer 7) are still the OSI numbers.
- 5, 6, 7: session, presentation, application
- 4: transport
- 3: network
- 1, 2: physical, data link
- Application: HTTP, DNS, TLS, SSH
- Transport: TCP, UDP
- Internet: IPv4, IPv6, ICMP
- Link: Ethernet, Wi-Fi
The exact headers, byte by byte
Each layer adds a known number of bytes. TCP adds a 20-byte header, up to 60 with options. UDP adds a fixed 8 bytes. IPv4 adds 20 bytes, up to 60 with options, and IPv6 adds a fixed 40-byte header. Ethernet II adds a 14-byte header (two 6-byte MAC addresses and a 2-byte EtherType) and a 4-byte FCS trailer. An 802.1Q VLAN tag adds 4 more bytes.
On the wire there is more: every frame is preceded by a 7-byte preamble and 1-byte start frame delimiter, and followed by a 12-byte interframe gap. So a full 1500-byte IP packet costs 1538 bytes of wire time. The smallest Ethernet frame is 64 bytes (header, 46-byte payload and FCS); shorter payloads are padded.
- TCP 20 to 60, UDP 8
- IPv4 20 to 60, IPv6 40 fixed
- Ethernet header 14 + FCS 4, VLAN tag +4
- Preamble and SFD 8, interframe gap 12
- Minimum frame 64 bytes, maximum standard 1518 (1522 tagged)
What changes at each hop, and what does not
As a packet crosses the internet, each router removes the incoming Ethernet frame, reads the IP header, decides the next hop and builds a brand-new frame for the next link with new source and destination MAC addresses. The IP addresses stay the same end to end, unless a NAT device rewrites them.
The router does change two IP fields: it lowers the TTL (hop limit in IPv6) by one, and in IPv4 it recalculates the header checksum because the TTL changed. The TCP segment inside is not touched by plain routers, which is why TCP's own checksum still works at the far end. Firewalls and load balancers may look deeper, but a pure router stops at layer 3.
- 1Frame arrives
Destination MAC is the router's
- 2Strip frame
Check FCS, remove Ethernet header
- 3Read IP header
Look up destination, TTL minus 1
- 4Find next hop MAC
ARP or neighbour cache lookup
- 5New frame out
New MACs, new FCS, same IPs
MTU, MSS and tunnel overhead
The MTU is the largest IP packet a link can carry: 1500 bytes on standard Ethernet. TCP's maximum segment size (MSS) is the data that fits after the IP and TCP headers: 1500 - 20 - 20 = 1460 bytes for IPv4, and 1440 for IPv6. Linux usually enables TCP timestamps, which add 12 option bytes, so each full segment really carries 1448 bytes.
Tunnels shrink the space further. PPPoE DSL links have an MTU of 1492. VXLAN adds 50 bytes of outer headers. WireGuard adds 60 bytes over IPv4 (80 over IPv6), which is why its default interface MTU is 1420. When a packet is too big and cannot be fragmented, it is dropped and an ICMP message should report it. If that message is blocked, you get the classic symptom: small requests work, big ones hang.
Learn it in 4 short steps
About 40m each. Track them with a timer in your plan.
- 1Map TCP/IP layers to OSI~40m
- 2Follow headers added at each layer~40m
- 3Name PDUs: segment, packet, frame~40m
- 4Explain MTU and overhead~40m
Key points
- PDUs: data, segment (TCP) or datagram (UDP), packet, frame, bits.
- Routers rewrite the frame at every hop but keep the IP packet's addresses (except with NAT).
- Ethernet MTU is usually 1500 bytes of payload per frame.
- Headers are overhead: about 40 bytes of TCP and IPv4 headers per packet.
Key terms
Tap a card to flip it. 0/4 known
Examples
# Show each layer's headers for one HTTP request
sudo tcpdump -i any -nn -e -c 5 'tcp port 80'
curl -s http://example.com > /dev/null
# -e prints the Ethernet (MAC) header tooWhy 1 Gbps Ethernet gives about 941 Mbps in iperf3
Step 1: one full frame uses 1538 bytes of wire time (1500 IP packet + 14 header + 4 FCS + 8 preamble + 12 gap). Step 2: with TCP timestamps, the data inside is 1500 - 20 IP - 32 TCP = 1448 bytes. Step 3: efficiency is 1448 / 1538 = 94.1 percent. Step 4: 94.1 percent of 1000 Mbps is about 941 Mbps, which is exactly the number iperf3 usually shows on a clean gigabit link. Nothing is broken; that is the overhead of the headers.
Finding the real path MTU with ping
Over a VPN, web pages half-load. Step 1: send a ping that exactly fills a 1500-byte packet: 1472 bytes of data + 8 ICMP header + 20 IPv4 header = 1500. Step 2: set the do-not-fragment flag with -M do. Step 3: if it fails with Message too long or no reply, lower the size until it works. Step 4: if 1392 works but 1393 does not, the path MTU is 1392 + 28 = 1420. Step 5: set the interface MTU or clamp TCP MSS on the VPN gateway to fit.
ping -M do -s 1472 -c 2 10.8.0.1 # 1500-byte packet, DF set
ping -M do -s 1392 -c 2 10.8.0.1 # 1420-byte packet
tracepath 10.8.0.1 # reports pmtu per hop
ip link show wg0 | grep mtuQuick reference
- PDUs: segment (TCP) or datagram (UDP), packet (IP), frame (Ethernet), bits
- Headers: TCP 20+, UDP 8, IPv4 20+, IPv6 40, Ethernet 14 + 4 FCS
- Ethernet MTU 1500, so TCP MSS is 1460 over IPv4 and 1440 over IPv6
- ping -M do -s 1472 tests a full 1500-byte path without fragmentation
- Routers change MACs and TTL at every hop; IPs stay the same unless NAT
- Tunnel MTUs: PPPoE 1492, WireGuard 1420 by default, VXLAN needs 50 extra bytes
- IPv6 minimum link MTU is 1280 bytes
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Capture three packets of a web request and identify the Ethernet, IP and TCP parts of one packet.
- Exercise 2medium
Compute the maximum UDP payload in one unfragmented packet over a standard Ethernet link, for IPv4 and for IPv6.
- Exercise 3hard
A VXLAN overlay runs over an underlay with MTU 1500. What inner MTU should VMs use? What underlay MTU would let VMs keep 1500?
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- What is the difference between a segment and a packet?
- A segment is the TCP unit: a TCP header plus data. A packet is the IP unit: an IP header plus whatever it carries, usually a segment. The segment sits inside the packet.
- What are jumbo frames?
- Ethernet frames with an MTU above 1500, commonly 9000 bytes. They cut header overhead and CPU work in data centres and storage networks, but every device on the path must support the same size.
- Does every router fragment packets that are too big?
- Only for IPv4 packets without the Don't Fragment bit. IPv6 routers never fragment; only the sending host can, after learning the path MTU from ICMPv6 Packet Too Big messages.
- Why does Wireshark show frames bigger than 1500 bytes?
- Usually because the network card does segmentation offload (TSO or GRO), joining or splitting packets in hardware. Wireshark sees them before splitting or after joining, so they look larger than the MTU.