# 1.7 Encapsulation Principle

The result of what happens when you combine layering and packet switching&#x20;

* Each packet contains data from multiple layers&#x20;
* The principle by which you organize information in packets so that you can maintain layers, yet let them share the contents of packets&#x20;

![](/files/-MgXJ3LJljGI9u0zaiqn)

![](/files/-MgXJCmaY-TsKIeU6swt)

* Each protocol layer has some headers, payload, footers&#x20;
  * E.x. IP packet header: source addr, dest addr
  * To send TCP segment with IP, make the TCP format the payload of the IP packet (IP packet "encapsulates" the TCP segment)&#x20;

### Encapsulation&#x20;

![](/files/-MgXJeOtKHmiku0oWLsn)

* Browsing a web using a computer connected through WiFi&#x20;
* Generates an HTTP GET request&#x20;
  * Payload of a TCP segment&#x20;
  * Payload of IP packet&#x20;
  * Payload of WiFi frame&#x20;

![](/files/-MgXK3ZWBABl0QS8m3s-)

![](/files/-MgXK8aDNkK7M8bzk_6a)

* Both correct&#x20;

![Wireshark ](/files/-MgXKUpmegsyQgxR3ghI)

### Encapsulation Flexibility&#x20;

* Able to layer recursively
* Transport layer security (TLS)&#x20;

![VPN ](/files/-MgXKn0bUIs8GhV2CicJ)

* Allows you to access private, protected network resources inside your office&#x20;
* TLS session is inside a TCP stream that terminates at the virtual private network gateway&#x20;

![Example ](/files/-MgXLfN9onT1OeV8UM5G)

![](/files/-MgXLlzwWX8NJRrjvsz7)

* How we take protocol layers and assemble them into packets in a way that's flexible and maintains their separation of concerns

&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://sliu583.gitbook.io/blog/networking/index/computer-networking-a-top-down-approach/stanford-cs144/chapter-1/1.7-encapsulation-principle.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
