Encapsulation and decapsulation
On this page
The request contains 83 bytes of text, but the receiving capture reports a 149-byte frame. Where do the extra bytes come from? Follow this one request to see which layer adds each part.
By the end, you can account for the added bytes and follow the request down the sender’s layers and up the receiver’s.
Before you start
Section titled “Before you start”Read TCP/IP and OSI models. This is supplied evidence from the course lab, not an exercise to run on your computer. The capture observes web:eth0, the receiving interface on web.
The author ran this command on laptop. Lowercase -s hides the progress display; uppercase -S keeps errors visible. The client, curl, prints the returned file while the capture records the request and response.
learner@laptop:~$ curl -sS http://10.77.20.80/hello.txtHello from web.learner@laptop:~$ Steps (3)
- Type
curl -sS http://10.77.20.80/hello.txt— Request hello.txt from web - Press Enter
- Output:
Hello from web.
Put information around the request
Section titled “Put information around the request”A header is information a protocol puts before the data it carries. The payload is the data carried inside that unit. A layer can treat the whole result from the layer above as its payload, including that layer’s header.
Encapsulation means enclosing data with the information another layer needs. In this example, each of three lower layers adds a header in front. The HTTP request remains inside them. Its text does not turn into an address or a program number.
The transport protocol here is TCP. It adds a header, making a segment: a TCP header and its payload. Its port numbers distinguish the communicating programs. You only need to recognize what those numbers name here.
The internet protocol here is IPv4. It puts its header before that segment, making a packet. The IP addresses name the source and destination machines. The segment, including its TCP header, becomes this packet’s payload.
The link protocol here is Ethernet. It puts a header before the packet, making a frame. The MAC addresses name the sending and receiving interfaces on the current link. The packet, including both inner headers, is the frame’s payload.
These unit names describe different amounts of the same captured data. Asking “how large is it?” needs a boundary: request text, segment, packet, or frame.
Step through the captured frame
Section titled “Step through the captured frame”Predict: which header is added last and therefore sits at the very front of the frame?
One request inside its headers
laptopsends · curl
- Applicationdata
- Transportsegment
- Internetpacket
- Linkframe
webreceives · web server
- Applicationdata
- Transportsegment
- Internetpacket
- Linkframe
The frame149 bytes
- Ethernetheader14 bytes
- IPv4header20 bytes
- TCPheader32 bytes
- HTTPdata83 bytes
One frame: 149 bytes
In the capturetcpdump -nn -e · frame 4
06:54:26.990134 02:77:20:00:00:01 > 02:77:20:00:00:80, ethertype IPv4 (0x0800), length 149: 10.77.10.10.36490 > 10.77.20.80.80: Flags [P.], seq 1:84, ack 1, win 63, options [nop,nop,TS val 2112827989 ecr 1913778413], length 83: HTTP: GET /hello.txt HTTP/1.1
027720000080027720000001080045000087ce8c40003f0639f10a4d0a0a0a4d14508e8a005032a1d654fe7386658018003f336d00000101080a7def32557211f0ed474554202f68656c6c6f2e74787420485454502f312e310d0a486f73743a2031302e37372e32302e38300d0a557365722d4167656e743a206375726c2f382e352e300d0a4163636570743a202a2f2a0d0a0d0a
curl -sS http://10.77.20.80/hello.txt, on Ubuntu 24.04.5 LTS, netlab 1.0, tcpdump 4.99.4, curl 8.5.0. The values are the capture's; the layer steps on both machines are the model. The request as it arrives on web's link after the router delivered it; the sender's steps are the model.Steps (9)
- HTTP data. curl on laptop has 83 bytes of HTTP to send: GET /hello.txt HTTP/1.1. Every layer below will carry these bytes without reading them.
- + TCP. The transport layer puts a TCP header in front: 32 bytes. It names the two programs by port number: 36490 to 80. Header plus data is now a segment.
- + IPv4. The internet layer adds an IPv4 header: 20 bytes. It names the two machines by IP address: 10.77.10.10 to 10.77.20.80. Now it is a packet.
- + Ethernet. The link layer adds an Ethernet header: 14 bytes. It names the interfaces at the two ends of one link, so each link gets its own. This frame was captured on web's link, after a router delivered it.
- On the link. The 149 bytes cross the network as one frame on each link. This is the frame tcpdump recorded at web:eth0: frame 4 of the capture.
- − Ethernet. web sees its own MAC address, 02:77:20:00:00:80, as the destination, so it accepts the frame. EtherType 0x0800 says the contents are IPv4. The Ethernet header comes off.
- − IPv4. The destination address 10.77.20.80 is web's own, and protocol 6 says the contents are TCP. The IPv4 header comes off.
- − TCP. Destination port 80 belongs to the web server. The TCP header comes off and the data goes to that program.
- HTTP data. The web server reads the same 83 bytes that curl wrote: GET /hello.txt HTTP/1.1.
Check your answer
The link header is added last, so it is first in the captured bytes.
The table gives the same boundaries without playing the stage. The Header column names the enclosing header. The application row counts the whole request text rather than a separate header.
| Layer and unit | Header | Bytes | What it names |
|---|---|---|---|
| Application: data | — | 83 | Action, path, fields |
| Transport: segment | TCP | 32 | Programs |
| Internet: packet | IPv4 | 20 | Machines |
| Link: frame | Ethernet | 14 | Interfaces |
The captured frame starts with the link header. An Ethernet frame also ends with a check value for detecting transmission errors. Capture tools normally do not show that frame check sequence; this virtual-interface capture does not include it. The reported length is therefore not a count of every physical signal sent on a cable.
The top of this diagram is the front of the frame: the Ethernet header (14 bytes), IPv4 header (20 bytes), TCP header (32 bytes), application data (the 83-byte HTTP request), and Ethernet check value appear in that order. The segment spans the TCP header and data; the packet spans the IPv4 header and segment; the frame spans the Ethernet header, packet and check value. The dashed check value is not in the capture, and this model omits individual header fields and does not scale the parts to their byte sizes.
Unwrap at the receiver
Section titled “Unwrap at the receiver”Decapsulation means removing the enclosing information as data moves up the receiving layers. The link layer reads its header and passes the packet upward. The internet layer reads its header and passes the segment upward. The transport layer handles its header and delivers the application data.
The receiver does not ask the application to interpret the Ethernet header. Each layer interprets its own information before passing the inner data onward. This is a model of responsibilities, not a claim that software must perform one visible operation per animation step.
For this request, the application receives the text the sender supplied. The headers add delivery information around it. This frame was captured after a router delivered it, so its source MAC belongs to the router’s site interface. It does not show the link header that laptop originally built.
Read the capture’s text
Section titled “Read the capture’s text”At the stage’s on-link step, open Capture. The first address pair is Ethernet’s source and destination MAC. After the frame length, another pair names the IP addresses with port numbers attached. The request’s first line appears at the end.
The bytes panel puts the outermost header first even though the text summary abbreviates many fields. Select a layer to connect its colored bytes with the fields panel. Unshown fields still occupy bytes; a summary line is not the complete header.
Mistakes to recognize
Section titled “Mistakes to recognize”“The data changes on the way down.” Here the request text remains the payload while headers are added around it.
“The receiver reads all headers at once.” The model passes the inner unit upward after each layer handles its own header.
“Packet is the right word for everything.” Specify frame, packet, segment, or application data when discussing sizes and boundaries.
“The MAC addresses stay the same all the way.” This capture names the interfaces on the receiving link. The next lesson compares both sides of the router.
Try it yourself
Section titled “Try it yourself”Goal: Account for a response frame from this same capture.
Use frame 8, carrying the file text from web toward laptop. Its summary is:
06:54:26.994220 02:77:20:00:00:80 > 02:77:20:00:00:01, ethertype IPv4 (0x0800), length 82: 10.77.20.80.80 > 10.77.10.10.36490: Flags [P.], seq 173:189, ack 84, win 64, options [nop,nop,TS val 1913778418 ecr 2112827993], length 16: HTTPThe captured frame has 82 bytes and its application payload has 16 bytes.
Fill the missing sizes and name the outermost header. Use the captured total, the application-data length, and the header boundaries established above.
| Part | Size in bytes |
|---|---|
| Ethernet header | ? |
| IPv4 header | ? |
| TCP header | ? |
| Application data | 16 |
| Captured total | 82 |
Expected: Three header sizes, their sum with the payload, and one header name.
Hint
The direction changes who sends. It does not reverse the order of headers within the frame.
Solution
The Ethernet header has 14 bytes, IPv4 has 20, and TCP has 32. Their sum with the 16-byte payload is 82 bytes. Ethernet is the outermost header. The application payload in this frame is the file text; the HTTP response’s descriptive lines traveled in a separate frame.
Leave for later
Section titled “Leave for later”Ethernet and Local Delivery explains MAC addresses. Understanding IPv4 Addresses explains IP addresses. TCP, UDP, and Ports explains ports and the other TCP fields.
- A header wraps a payload with another layer’s information.
- TCP segments sit inside IP packets, which sit inside Ethernet frames here.
- The receiver handles the headers in the opposite order.
- Captured length excludes the Ethernet check value in this evidence.
Next, Following one exchange compares the request at four points along its path.
Further reading
Section titled “Further reading”- RFC 9293, §3.1: TCP header format.
- RFC 791, §3.1: IPv4 header format.
- RFC 894: IP over Ethernet.
- Wireshark: Ethernet capture limits, for the frame check sequence normally missing from captures.