> For the complete documentation index, see [llms.txt](https://netsec.nerd-cafe.ir/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://netsec.nerd-cafe.ir/network-engineering/comptia-network+/n10-007/encapsulation-and-de-encapsulation-process-in-networking.md).

# Encapsulation & De-encapsulation Process in Networking

Nerd Cafe

### <mark style="color:blue;">**Introduction**</mark>

Encapsulation and de-encapsulation are fundamental concepts in networking that describe how data is packaged and transmitted across a network. These processes follow the <mark style="color:red;">**OSI (Open Systems Interconnection) model**</mark> and the <mark style="color:red;">**TCP/IP model**</mark> to ensure reliable communication between devices.

### <mark style="color:blue;">**1. Understanding Encapsulation & De-encapsulation**</mark>

#### **Encapsulation**

* Encapsulation is the process of adding headers (and sometimes trailers) to data as it moves down the OSI or TCP/IP model layers.
* Each layer of the model adds specific information needed for data transmission, such as source/destination addresses, error detection, and control information.

#### **De-encapsulation**

* De-encapsulation is the reverse process, where the headers and trailers are removed as the data moves up the layers to be read by the receiving application.
* The receiving device extracts useful data and forwards it to the next layer until it reaches the application layer.

<figure><img src="https://2804731566-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLOszSitBb46QATDLUtW4%2Fuploads%2F60wmXsC4G6mc9a7nCAbd%2F0494-encap-decap.jfif?alt=media&amp;token=4dd89ff6-90c2-47e8-a558-929118d27ef7" alt=""><figcaption><p>ncapsulation &#x26; De-encapsulation</p></figcaption></figure>

### <mark style="color:blue;">**2. Step-by-Step Encapsulation Process (Sending Data)**</mark>

Let's assume a user sends an email over a network. Here's how the data is encapsulated:

#### <mark style="color:green;">**Step 1: Application Layer (Layer 7)**</mark>

* The user writes an email using an email application (e.g., Outlook, Gmail).
* The email is converted into **raw data** by the application.

📌 **Example:**

* Data = `"Hello, how are you?"`

#### <mark style="color:green;">**Step 2: Transport Layer (Layer 4)**</mark>

* The transport layer segments the data and adds a **header** with port numbers for the sender and receiver.
* The header ensures that the data is delivered to the correct application on the destination system.
* Protocols used: **TCP (Transmission Control Protocol)** or **UDP (User Datagram Protocol).**

📌 **Example:**

* **TCP Header:** Includes source port, destination port, sequence number, and acknowledgment number.

🔹 **Segmented Data Example:**

```css
[ TCP Header | "Hello, how are you?" ]
```

#### <mark style="color:green;">**Step 3: Network Layer (Layer 3)**</mark>

* The network layer encapsulates the segment into a **packet** by adding an **IP header**.
* The IP header contains the **source and destination IP addresses**, helping the data reach the correct destination.

📌 **Example:**

* **IP Header:**
  * Source IP: `192.168.1.10`
  * Destination IP: `8.8.8.8`

🔹 **Packet Example:**

```css
[ IP Header | TCP Header | "Hello, how are you?" ]
```

#### <mark style="color:blue;">**Step 4: Data Link Layer (Layer 2)**</mark>

* The data link layer encapsulates the packet into a **frame** by adding a **MAC (Media Access Control) header and trailer.**
* The MAC header contains **source and destination MAC addresses**, ensuring correct delivery within the local network.

📌 **Example:**

* **MAC Header:**
  * Source MAC: `00:1A:2B:3C:4D:5E`
  * Destination MAC: `00:2B:3C:4D:5E:6F`
* **Frame Trailer:** Contains error detection information (e.g., **CRC - Cyclic Redundancy Check**).

🔹 **Frame Example:**

```css
[ MAC Header | IP Header | TCP Header | "Hello, how are you?" | Trailer ]
```

#### <mark style="color:green;">**Step 5: Physical Layer (Layer 1)**</mark>

* The frame is converted into **bits (1s and 0s)** and transmitted over the network medium (e.g., Ethernet cable, Wi-Fi, fiber optics).

📌 **Example:**

```
101101011010010110110101010...
```

* The data is now sent to the destination computer.

### <mark style="color:blue;">**3. Step-by-Step De-encapsulation Process (Receiving Data)**</mark>

Once the destination computer receives the bits, it follows the <mark style="color:red;">**de-encapsulation**</mark> process by moving **up the OSI model layers**:

#### <mark style="color:purple;">**Step 1: Physical Layer (Layer 1)**</mark>

* The received **bits (0s and 1s)** are converted back into a **frame**.

#### <mark style="color:purple;">**Step 2: Data Link Layer (Layer 2)**</mark>

* The data link layer checks the **MAC address**. If it matches the device’s MAC address, it removes the **MAC header and trailer** and forwards the data to the **network layer**.

📌 **Frame before processing:**

```css
[ MAC Header | IP Header | TCP Header | "Hello, how are you?" | Trailer ]
```

📌 **Frame after processing:**

```css
[ IP Header | TCP Header | "Hello, how are you?" ]
```

#### <mark style="color:purple;">**Step 3: Network Layer (Layer 3)**</mark>

* The network layer checks the **IP address** to ensure it matches the device’s IP.
* If the IP is correct, the **IP header** is removed, and the data is sent to the **transport layer**.

📌 **Packet before processing:**

```css
[ IP Header | TCP Header | "Hello, how are you?" ]
```

📌 **Packet after processing:**

```css
[ TCP Header | "Hello, how are you?" ]
```

#### <mark style="color:purple;">**Step 4: Transport Layer (Layer 4)**</mark>

* The transport layer checks the **port number** to determine the correct application.
* The **TCP header** is removed, and the data is sent to the **application layer**.

📌 **Segment before processing:**

```css
[ TCP Header | "Hello, how are you?" ]
```

📌 **Segment after processing:**

```css
"Hello, how are you?"
```

#### <mark style="color:purple;">**Step 5: Application Layer (Layer 7)**</mark>

* The **raw data** is handed over to the email application (e.g., Gmail, Outlook).
* The user sees the email `"Hello, how are you?"` in the inbox.

### <mark style="color:blue;">Summary Table: Encapsulation vs. De-encapsulation</mark>

<table><thead><tr><th width="160">Layer</th><th width="287">Encapsulation Process (Sending)</th><th>De-encapsulation Process (Receiving)</th></tr></thead><tbody><tr><td><ol start="7"><li>Application</li></ol></td><td>Creates data (e.g., email)</td><td>Receives data (e.g., email content)</td></tr><tr><td><ol start="4"><li>Transport</li></ol></td><td>Adds TCP/UDP header (Port Numbers)</td><td>Removes TCP/UDP header</td></tr><tr><td><ol start="3"><li>Network</li></ol></td><td>Adds IP header (Source &#x26; Destination IP)</td><td>Removes IP header</td></tr><tr><td><ol start="2"><li>Data Link</li></ol></td><td>Adds MAC header &#x26; trailer</td><td>Removes MAC header &#x26; trailer</td></tr><tr><td><ol><li>Physical</li></ol></td><td>Converts to bits and sends</td><td>Converts bits back to frames</td></tr></tbody></table>

### <mark style="color:blue;">Keywords</mark>

`Encapsulation`, `De-encapsulation`, `OSI Model`, `TCP/IP Model`, `Data Transmission`, `Network Layer`, `Transport Layer`, `Application Layer`, `Physical Layer`, `Data Link Layer`, `IP Header`, `MAC Address`, `TCP Header`, `UDP Header`, `Network Packet`, `Ethernet Frame`, `Protocol Stack`, `Bits and Bytes`, `Wireshark Analysis`, `Network Communication`, `نتورک پلاس`
