Data Transmission - Encapsulation and Decapsulation
Understanding Encapsulation and Decapsulation in Networking
Data Transmission - Encapsulation and Decapsulation
Introduction
When data is transmitted over a network from a source to a destination, it undergoes a process known as encapsulation and decapsulation. These are essential concepts in networking, ensuring data is properly packaged for transmission and then unpacked at the receiving end.
In this blog, we’ll explore what these processes are, how they work across the OSI model, and what headers are involved at each stage.
What is Encapsulation?
- Encapsulation is the process of adding protocol-specific headers (and sometimes trailers) to data as it moves down the layers of the OSI or TCP/IP model before being sent over the network.
- Protocol information can be added before and after the data. If the information is added before the data, it is known as a
header
. If the information is added after the data, it is known as atrailer
. - Think of it like mailing a package:
- You write a letter (data),
- Put it in an envelope (header),
- Attach a stamp (IP address),
- And finally give it to the postman (physical layer).
Protocol Data Unit(PDU)
Layers | Data Form | Description |
---|---|---|
1. Application, Presentation, Session Layers (Layers 7–5) | Data | At these top layers, the data is in its original form (e.g., an email, a file, or a message). No headers or addressing is applied yet. |
2. Transport Layer (Layer 4) | Segment (TCP) or Datagram (UDP) | The data is broken into segments and each is assigned: - Port numbers (e.g., HTTP = port 80) - Sequence numbers (for ordering/reassembly) |
3. Network Layer (Layer 3) | Packet | Each segment is encapsulated into a packet, which includes: - Source and destination IP addresses - Routing information for delivery across networks |
4. Data Link Layer (Layer 2) | Frame | Each packet is placed inside a frame, which includes: - MAC addresses - Error checking (CRC) Suitable for delivery over a single hop (e.g., between two routers or devices) |
5. Physical Layer (Layer 1) | Bits | The frame is finally converted into a stream of binary bits (0s and 1s) and transmitted as electrical, optical, or radio signals. |
</br>
Basis for Comparison | Frame | Packet |
---|---|---|
Basic | Frame is the data link layer protocol data unit. | Packet is the network layer protocol data unit. |
Associated OSI Layer | Data link layer | Network layer |
Includes | Source and destination MAC address. | Source and destination IP address. |
Correlation | Segment is encapsulated within a packet. | Packet is encapsulated within a frame. |
What is Decapsulation?
- Decapsulation is the reverse. As the data reaches the destination, each layer removes its corresponding header/trailer, passing the core data up the stack until it reaches the application.
OSI Model - Layer-by-Layer Journey
Encapsulation Process
Layer | Description | Header Includes | Example |
---|---|---|---|
Application (Layer 7) | User Data : The actual message (e.g., an HTTP request). | No headers are added here; it’s just data generated by the application. | A user sends an email using Gmail. |
Presentation (Layer 6) | Data is formatted, compressed, or encrypted (e.g., using SSL/TLS). | (Optional) Encryption metadata like certificates. | Formatting or encrypting data for secure transmission. |
Session (Layer 5) | Manages session creation, maintenance, and termination. | Session identifiers for tracking communication flows. | Maintaining a session for a video call. |
Transport (Layer 4) | Segment header : Ensures reliable or fast delivery. | Source/Destination Port Numbers, Sequence/Acknowledgment Numbers, Flags, Window Size, Checksum. | TCP header used in a file transfer to track segments. |
Network (Layer 3) | Handles logical addressing and routing. | Source/Destination IP Address, TTL (Time To Live), Protocol Identifier, Header Checksum. | IP header determines how the packet reaches a different network. |
Data Link (Layer 2) | Responsible for node-to-node delivery within the same network. | Source/Destination MAC Address, Frame Type, Error Checking (CRC), Trailer (optional): Frame Check Sequence (FCS). | An Ethernet frame between your PC and the local router. |
Physical (Layer 1) | Converts the frame into bits and transmits them over the medium (e.g., electrical signals, light pulses, or radio waves). | No headers, just raw binary transmission. | Transmitting bits over Wi-Fi or Ethernet. |
Decapsulation Process
- At the destination, each layer performs the inverse operation:
Layer | Decapsulation Process | Example |
---|---|---|
Physical (Layer 1) | Receives the bits and converts them into a frame for the Data Link Layer. | Bits transmitted over Wi-Fi or Ethernet are received by the network card. |
Data Link (Layer 2) | Reassembles the frame and strips the MAC header and trailer. | Removes Ethernet frame headers to extract the IP packet. |
Network (Layer 3) | Uses the IP address to verify it’s the right recipient and removes the IP header. | Extracts the TCP segment from the IP packet. |
Transport (Layer 4) | Reorders segments, removes TCP/UDP headers, and passes the data to the Session Layer. | Reconstructs the application data from TCP segments. |
Session (Layer 5) | Manages session information and passes the data to the Presentation Layer. | Ensures the session remains active for the communication. |
Presentation (Layer 6) | Decrypts, decompresses, or formats the data and passes it to the Application Layer. | Decodes encrypted data for the application. |
Application (Layer 7) | Processes the data and delivers it to the user or application. | Displays the content of a webpage in the browser. |
TCP IP Model - Layer-by-Layer Journey
Communication Between Source and Destination
Real-World Example: Loading a Website
- Let’s say you access https://example.com:
Layer | Process |
---|---|
Application Layer | Your browser sends an HTTP GET request. |
Transport Layer | TCP adds port info, ensuring reliability. |
Network Layer | IP addresses the packet from your laptop to the web server. |
Data Link Layer | Ethernet/MAC addresses ensure the router receives it. |
Physical Layer | Bits are transmitted over Wi-Fi or Ethernet. |
- On the server, decapsulation reconstructs the request and delivers the data to the web application.
Adjacent vs Same-Layer Interaction
Adjacent Layer Interaction
- A higher layer uses services of the layer directly below it.
- E.g., Transport layer uses Network layer to send segments.
Same-Layer Interaction
:- Each layer at the sender communicates logically with its peer layer at the receiver using standardized headers.
- E.g., the transport layer on your computer talks to the transport layer on the web server via TCP.
Key Takeaways
Encapsulation adds headers; decapsulation removes them. Headers at each layer carry important control information. Understanding this process helps in troubleshooting network issues and designing efficient communication systems.
This post is licensed under CC BY 4.0 by the author.