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

![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVORxAomcgtzVVUqmws%2F-MgXIccO0iBYd6UUg4xM%2F-MgXJ3LJljGI9u0zaiqn%2Fimage.png?alt=media\&token=bd44d1e5-11a5-4567-92ca-f9e3a360198d)

![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVORxAomcgtzVVUqmws%2F-MgXIccO0iBYd6UUg4xM%2F-MgXJCmaY-TsKIeU6swt%2Fimage.png?alt=media\&token=06a2df1b-7806-48bb-8fca-87baf4b30253)

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

![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVORxAomcgtzVVUqmws%2F-MgXIccO0iBYd6UUg4xM%2F-MgXJeOtKHmiku0oWLsn%2Fimage.png?alt=media\&token=b90c60b2-1e61-44c4-a9eb-c3f91c7b7260)

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

![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVORxAomcgtzVVUqmws%2F-MgXIccO0iBYd6UUg4xM%2F-MgXK3ZWBABl0QS8m3s-%2Fimage.png?alt=media\&token=5254c119-4f78-40d8-aab5-3e739c1e4388)

![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVORxAomcgtzVVUqmws%2F-MgXIccO0iBYd6UUg4xM%2F-MgXK8aDNkK7M8bzk_6a%2Fimage.png?alt=media\&token=1f9ac752-1283-4f53-aeb7-89dd7a2279e6)

* Both correct&#x20;

![Wireshark ](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVORxAomcgtzVVUqmws%2F-MgXIccO0iBYd6UUg4xM%2F-MgXKUpmegsyQgxR3ghI%2Fimage.png?alt=media\&token=dcf906f0-1c9c-4fef-b809-0e0f11844f73)

### Encapsulation Flexibility&#x20;

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

![VPN ](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVORxAomcgtzVVUqmws%2F-MgXIccO0iBYd6UUg4xM%2F-MgXKn0bUIs8GhV2CicJ%2Fimage.png?alt=media\&token=0f6556d6-7096-4212-8145-487e09d00386)

* 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 ](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVORxAomcgtzVVUqmws%2F-MgXIccO0iBYd6UUg4xM%2F-MgXLfN9onT1OeV8UM5G%2Fimage.png?alt=media\&token=96ddf8b2-3d11-4503-9f4d-98be06528b77)

![](https://2097630930-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MVORxAomcgtzVVUqmws%2F-MgXIccO0iBYd6UUg4xM%2F-MgXLlzwWX8NJRrjvsz7%2Fimage.png?alt=media\&token=2d0fdece-e8d5-404e-b982-a4d0d900cf96)

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

&#x20;
