Encapsulation and Decapsulation

How data is wrapped with headers and trailers as it moves through the network layers.

The Need for Encapsulation

When you send a message over a network, it doesn't just go as a single, simple chunk of data. A complex process is required to ensure it gets to the right destination, is free of errors, and is understood by the receiving device. Encapsulation is the crucial mechanism that makes this possible in a layered network architecture like the OSI or TCP/IP models.

Think of it like sending an international letter. You don't just write your message on a piece of paper and hand it to a pilot. You put it in an envelope (adding addresses), which goes into a local mailbag (for local sorting), which then goes into a shipping container (for international transport). Each step adds a layer of packaging and instructions needed for that specific part of the journey. This is exactly what encapsulation does for your data.

The Sending Process: Data Flowing Down the Stack

Encapsulation occurs on the sending device as data moves down from the highest layer (Application) to the lowest (Physical). At each layer, a header (and sometimes a trailer) is added to the data received from the layer above. This "wrapped" data at each layer is called a .

Walk through the OSI stack

Toggle the direction and explore what each layer adds or removes, then compare it with the classic office memo analogy.

Flow
View

Step 1 of 7

Layer 7 路 Application

Data
What happens here

User intent becomes application payload that can be formatted, secured and passed down the stack.

Headers added so far
Encapsulation stack
L7Data
Key responsibilities
  • Provides network services to end-user applications such as messaging, file transfer and directories.
  • Negotiates capabilities like authentication, resource sharing and service quality.
Typical protocols
HTTP
SMTP
DNS

Selected layer

Drag the handle or tap a tile to change layers.

Layer 7 路 Application
L7L6L5L4L3L2L1
  1. Application, Presentation, Session Layers (7-5): The user application (e.g., web browser, email client) creates the initial Data. It is formatted, compressed, or encrypted as needed.
  2. Transport Layer (4): The data is broken into smaller chunks. The Transport Layer adds a header containing port numbers (to identify the application) and sequence numbers (for reassembly). This PDU is now a Segment (using TCP) or Datagram (using UDP).
  3. Network Layer (3): The segment is encapsulated with a header containing logical addresses. This creates a Packet.
    • The is the key information here, specifying the final source and destination on the internet.
  4. Data Link Layer (2): The packet is encapsulated with a header and a trailer, creating a Frame.
    • The header contains physical addresses, known as , for the next hop on the local network.
    • The trailer includes a Frame Check Sequence (FCS) for error detection, often calculated using CRC.
  5. Physical Layer (1): The frame is converted into a stream of Bits and transmitted over the physical medium (e.g., as electrical voltages, light pulses, or radio waves).

The Receiving Process: Data Flowing Up the Stack

The receiving device performs the reverse process, known as Decapsulation. As the data moves up the stack, each layer reads the information in its corresponding header, processes it, and then removes the header before passing the remaining PDU to the layer above.

Walk through the OSI stack

Toggle the direction and explore what each layer adds or removes, then compare it with the classic office memo analogy.

Flow
View

Step 1 of 7

Layer 1 路 Physical

Bits
What happens here

Samples the incoming signal, recovers bits and hands them to the data link layer.

Headers still attached
Encapsulation stack
L7DataL6DataL5DataL4SegmentL3PacketL2FrameL1Bits
Key responsibilities
  • Defines voltage levels, timing, connectors and media specifications for transmission.
  • Encodes bits onto the medium and recovers them at the receiver with acceptable error rates.
Typical protocols
Ethernet PHY
DSL
802.11 PHY

Selected layer

Drag the handle or tap a tile to change layers.

Layer 1 路 Physical
L1L2L3L4L5L6L7
  1. Physical Layer (1): Receives the electrical/optical signals and converts them back into bits, assembling them into a Frame.
  2. Data Link Layer (2): Reads the source and destination MAC addresses. It verifies the FCS to check for transmission errors. If everything is correct, it strips off the frame's header and trailer and passes the Packet up to the Network Layer.
  3. Network Layer (3): Examines the IP header to verify the packet has reached its final destination network. It then strips the IP header and passes the Segment/Datagram up to the Transport Layer.
  4. Transport Layer (4): Processes the header information (e.g., using sequence numbers to reassemble the data in the correct order). Once reassembled, it strips the transport header and delivers the raw Data to the correct application based on the port number.
  5. Application, Presentation, Session Layers (7-5): The upper layers receive the data, reverse any compression or encryption, and present it to the end-user application in a usable format.
    Encapsulation and Decapsulation | Teleinf Edu