Kahibaro
Discord Login Register

3.10 Encapsulation & Decapsulation

Building and Unwrapping Network Data

Encapsulation and decapsulation describe how data is prepared for travel across a network and how it is processed when it arrives. In the context of the OSI model, they explain how each layer adds or removes its own information to help data move correctly from one device to another.

This chapter focuses on the process itself, not on the full details of each layer, which are covered in their own chapters.

The Big Idea: Wrapping Data in Layers

When an application on your computer sends data, that data does not go to the network as one raw block. Instead, it is wrapped in several layers of information as it moves down the OSI stack. At the other end, those layers are removed as the data moves up the stack to the receiving application.

The OSI layers involved (from top to bottom) are:

Application
Presentation
Session
Transport
Network
Data Link
Physical

Encapsulation means adding headers, and sometimes trailers, to data as it travels from the Application layer down to the Physical layer. Decapsulation means removing those headers and trailers as the data goes from the Physical layer back up to the Application layer on the destination.

Names of Data at Each Layer

Although you can think of the data as a single “blob,” networking uses different names for it at different OSI layers. What changes is the extra information added around the original data.

OSI LayerCommon Name for Data
ApplicationData
PresentationData
SessionData
TransportSegment (TCP) / Datagram (UDP)
NetworkPacket
Data LinkFrame
PhysicalBits

The key point is that each lower layer adds its own wrapper around what came from the layer above.

Structure of Encapsulation

At each step down, a layer takes the data it receives, treats it as its own “payload,” and adds its own header in front of it. Some layers, notably the Data Link layer, also add a trailer at the end.

Conceptually, encapsulation looks like this, starting from what the Application layer produces:

  1. Application, Presentation, Session
    The three top layers generate or transform the user data. The result is still simply called data.
  2. Transport layer
    The Transport layer takes the data and adds a transport header, for example a TCP or UDP header. The result is a transport segment (TCP) or transport datagram (UDP).
  3. Network layer
    The Network layer receives the segment and adds a network header, for example an IP header. The result is a packet.
  4. Data Link layer
    The Data Link layer receives the packet and adds a data link header and usually a data link trailer. The result is a frame.
  5. Physical layer
    The Physical layer converts the frame into a stream of bits and then into electrical, optical, or radio signals that can travel over the medium.

You can imagine the result at each stage as:

$$\text{New PDU} = \text{Layer Header} + \text{Payload from Above} + \text{(Optional Trailer)}$$

where PDU is “Protocol Data Unit,” the general term for “the data at this layer.”

Encapsulation rule:
Each layer treats everything from the layer above as a single payload and does not need to understand its internal structure. It only adds its own header, and, if used, its own trailer.

An Example Walkthrough: From App to Wire

Consider a simple example of a web browser requesting a webpage from a server. The details of HTTP, TCP, and IP are covered elsewhere, so here we only focus on how they stack.

  1. Application, Presentation, Session
    The browser creates an HTTP request. That request is the user data. This data then moves down without additional network-specific headers at these top three layers in the OSI perspective.
  2. Transport layer
    The Transport layer chooses a protocol such as TCP. It adds a TCP header that, among other things, includes source and destination port numbers. Now the unit is a TCP segment:
    TCP header + HTTP data.
  3. Network layer
    The Network layer adds an IP header with source and destination IP addresses. Now the unit is a packet:
    IP header + TCP header + HTTP data.
  4. Data Link layer
    On a typical Ethernet network, the Data Link layer adds an Ethernet header with source and destination MAC addresses, and an Ethernet trailer with a checksum (FCS) for error detection. Now the unit is a frame:
    Ethernet header + IP header + TCP header + HTTP data + Ethernet trailer.
  5. Physical layer
    The Physical layer converts this frame into bits and sends them as electrical, optical, or radio signals on the physical medium.

Throughout this process, the inner content, the HTTP request, is not changed by the lower layers. They only wrap it.

Decapsulation: Unwrapping at the Destination

At the destination, the reverse process happens. The device receives raw signals and reconstructs the original data by removing one layer of wrapping at a time.

  1. Physical layer
    The Physical layer converts incoming signals into bits and hands those bits to the Data Link layer.
  2. Data Link layer
    The Data Link layer organizes bits into a frame, checks the trailer, and uses the header to see if the frame is for this device. If it is, the Data Link layer removes its own header and trailer, and passes the remaining packet up.
  3. Network layer
    The Network layer examines the IP header, checks whether the destination IP matches this device, and possibly processes routing if needed. It then removes the IP header and passes the remaining transport segment up.
  4. Transport layer
    The Transport layer reads the transport header, uses the destination port to identify the correct application, handles delivery, and removes the transport header. It passes the raw application data up.
  5. Session, Presentation, Application
    These layers interpret the data as an HTTP response, web content, or other application information, and eventually display it or handle it for the user.

At each step, the layer only removes its own header and trailer. It does not remove or alter the headers belonging to other layers.

Decapsulation rule:
Each layer accepts the PDU from the layer below, checks and processes its own header and trailer, removes them, and passes the remaining payload up to the next higher layer.

Layer Independence and Encapsulation

Encapsulation and decapsulation help keep layers independent from each other. Each layer follows two key ideas:

First, a layer does not need to understand the exact content of the payload it receives from the layer above. It only needs to know how to attach and interpret its own header and trailer.

Second, a layer provides services to the layer above without exposing low level details. For example, the Transport layer can provide “reliable delivery” to applications without the application needing to know how the network routes packets or what physical medium is used.

This is possible because encapsulation hides the complexity of inner layers from outer layers and vice versa. As long as each layer follows its rules for adding and removing its own headers and trailers, the entire stack can function even when technologies inside individual layers change.

Addressing and Multiplexing Through Encapsulation

Encapsulation also allows multiple kinds of addressing to coexist in the same unit of transmitted data.

A frame often contains:

Ethernet header with MAC addresses.
IP header with IP addresses.
Transport header with port numbers.

Each layer uses its own kind of address. MAC addresses help devices on the local network deliver frames. IP addresses help routers deliver packets across networks. Port numbers help the Transport layer deliver data to the correct application on one device.

Because each layer’s header is encapsulated within the next layer’s PDU, the network can route data correctly from one application on a source device to one application on a destination device, even when many applications are using the network at the same time. This is sometimes called multiplexing, since multiple separate conversations share the same network links.

Encapsulation, Overhead, and MTU

Each header and trailer added during encapsulation consumes extra bytes. This extra data is called protocol overhead. Overhead is necessary for control information, but if it becomes too large it can reduce the fraction of each frame that is actual user data.

There is also a limit to how large each PDU can be at certain layers. For example, the Data Link layer often has a maximum frame size. At the Network layer there is a related concept called Maximum Transmission Unit, or MTU, which limits the size of packets carried over a particular link.

If the payload plus headers exceed these limits, the Network layer or other mechanisms may have to split the data into multiple packets or frames. Those are then reassembled later. The existence of MTU is one reason the Transport layer might break application data into several smaller segments before handing them to the Network layer.

Encapsulation and overhead rule:
Every additional protocol header and trailer increases overhead. More overhead means more bytes on the wire for the same amount of user data, so protocol design must balance needed control information against efficiency.

Encapsulation Across Multiple Networks

When data travels across the internet, it usually passes through many physical and data link technologies between source and destination. For example, your computer might use Ethernet to connect to a home router, which then uses a different link to your ISP.

In such a journey, the inner layers and outer layers behave differently:

The Transport and Network layer headers (such as TCP and IP headers) usually remain the same end to end, from the original source to the final destination.

The Data Link layer header and trailer usually change at every hop, because different physical links and data link technologies may be used between routers. Each link layer only needs to deliver frames from one device to the next.

On each link between routers, the packet is encapsulated in a new frame for that particular data link technology, then decapsulated again at the next router, which checks and removes the frame header and trailer but keeps the IP packet intact.

So encapsulation can happen at multiple hops, not just at the original sender. Each hop performs encapsulation and decapsulation at the lower layers while the higher layer headers remain unchanged.

Summary of the Process

Encapsulation and decapsulation describe how data passes through the OSI layers from source to destination.

At the sender, the data starts at the Application layer and is progressively wrapped with headers (and trailers) as it moves down the layers until it becomes bits on the wire at the Physical layer.

At the receiver, the reverse process occurs. Each layer strips its own header and trailer, interprets control information, and passes the remaining payload up to the next layer until the original data reaches the Application layer.

This layered wrapping and unwrapping allows different kinds of addresses and control information to coexist in a structured way. It keeps each layer independent but coordinated, and makes it possible to send data reliably and flexibly across very different kinds of networks.

Views: 43

Comments

Please login to add a comment.

Don't have an account? Register now!