> For the complete documentation index, see [llms.txt](https://sliu583.gitbook.io/blog/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sliu583.gitbook.io/blog/networking/index/computer-networking-a-top-down-approach/stanford-cs144/chapter-1/1.7-encapsulation-principle.md).

# 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;
