The OSI model can be confusing as it’s very abstract. Educators tend to throw these terms immediately at those who aren’t familiar with it. Instead, you’re more likely to understand it by running through an example. So, let’s try to build your understanding of the model through a concrete example like an HTTP POST request. Only after going through the example will you get the definitions of the OSI model.
When we send a file across the internet, we expect the computer that’s receiving the data to get the same file right? To understand how this is achieved it’s important to understand the underlying abstract levels. We don’t just convert the file to a signal and then send it across the internet expecting the network to understand gibberish. Protocols is what keeps the system together. This is what the OSI model is all about.
Bare with me through this part, this’ll all make sense in the pseudocode after this.
Imagine an HTTP POST request where a user submits a form with JSON data to a web server. Let’s see how each OSI layer processes this request.
Layer 7 (Application Layer):
The HTTP POST request is created, notice the content-type, and HTTP headers:
POST /submit HTTP/1.1
Host: example.com
Content-Type: application/json
Body: {"name": "Bob", "age": 30}
Layer 6 (Presentation Layer):
The HTTP request is encrypted using TLS to ensure security:
Encrypted(POST /submit HTTP/1.1...)
Layer 5 (Session Layer):
A TLS session is established between the client and server, managing the connection:
Layer 4 (Transport Layer - TCP):
The encrypted request is segmented for transmission. Each segment contains:
Layer 3 (Network Layer - IP):
Each TCP segment will have its own packet, IP addresses (source and destination) are added. These IP packets are responsible for ensuring that data is routed to the correct destination.
Layer 2 (Data Link Layer):
The IP packets are framed with MAC addresses for local network communication (like through Ethernet). Frames ensure that data can hop between devices within the same local network.
Layer 1 (Physical Layer):
The frames are converted into electrical or optical signals and sent over physical media (e.g., cables, Wi-Fi) to the server.