How the OSI Model Works
Introduction
Welcome to Part 3 of the Network Fundamentals study notes! If you haven’t already, we recommend watching the video first.
In this part, we look at the OSI model — a framework that helps us understand how networking protocols work together. We’ll walk through each of the seven layers, see how data is packaged up as it travels through the stack, and finish with a real-world example of a web browser talking to a server.
Why We Need a Model
All devices on a network need hardware and software that lets them communicate. As we’ve seen, they do this using protocols — agreed-upon rules for how data is sent and received. But there isn’t just one protocol doing all the work. Several protocols need to work together to get any job done, and keeping track of how they all interact can get complicated.
That’s where network models come in. A model gives us a framework for understanding how everything fits together, without needing to know every specific detail up front.
The Letter Analogy
Think about sending a letter. You write it, put it in an envelope, address it, stamp it, and drop it at the post office. From there, staff sort it, load it onto the right truck, and it eventually arrives at the destination post office — where a postman delivers it to your friend’s door.
This is a model. Each step has a role, and the details underneath can change — maybe you’re sending a package instead of a letter, or using a courier instead of the post office — but the overall process still makes sense. Network models work the same way. We can understand the big picture, and then zoom in on the details as needed.
The OSI Model
The OSI model (Open Systems Interconnection) breaks networking into seven layers. From bottom to top, they are:
- Physical
- Data Link
- Network
- Transport
- Session
- Presentation
- Application
A handy mnemonic to remember the order from bottom to top is: Please Do Not Throw Sausage Pizza Away.
Notice that these layers are all generic — there’s no “Ethernet layer” or “email layer”. The OSI model isn’t about specific technologies, but rather about how different technologies fit into the overall network stack. Ethernet, for example, lives at the Data Link and Physical layers. IP lives at the Network layer. This is what makes the model so useful: it lets you place any technology in context.
The Seven Layers
Layer 7 – Application
The application layer is not the application itself — it’s how the application accesses the network. Examples include web browsing (HTTP), email (SMTP), file transfer (FTP), and management sessions like SSH and Telnet.
Layer 6 – Presentation
The presentation layer handles data format. If data from the application layer needs to be converted to a format the rest of the network can understand, this is where it happens. It also covers services like encryption and compression, and includes file formats such as images and video.
Layer 5 – Session
An application may need to communicate with several remote endpoints at once. The session layer keeps track of each of these conversations — each one is called a session. It handles the establishment and management of those sessions. Remote procedure calls and service requests live here.
Layer 4 – Transport
The transport layer is responsible for getting data between processes on two endpoints. The two most common protocols here are TCP and UDP.
One important job at this layer is breaking large amounts of data into manageable chunks. If a transfer fails halfway through, only the missing chunk needs to be resent — not the whole file. This also allows multiple applications to share the network at the same time rather than one hogging the connection. This is called multiplexing.
Each chunk of data at this layer has port numbers added in a header — a source port and a destination port. These track which application the data belongs to. For example, web traffic uses destination port 80 (HTTP). The block of data at this layer is called a segment (TCP) or a datagram (UDP).
Layer 3 – Network
The network layer handles addressing and routing — getting data from one network to another. The most common protocol here is IP (Internet Protocol). At this layer, source and destination IP addresses are added as a header. Once these are added, the chunk of data is called a packet.
Layer 2 – Data Link
The data link layer handles getting data from one device to the next device — not the final destination, just the next hop. A well-known protocol at this layer is Ethernet, which uses MAC addresses.
At this layer, another header is added (containing source and destination MAC addresses), and a trailer is added at the end with error-checking information. Once the header and trailer are added, the chunk is called a frame.
The data link layer has two sub-layers:
- LLC (Logical Link Control) – translates between the network layer and the data link layer.
- MAC (Media Access Control) – adds the headers and trailers, and handles error correction.
An important note: as data crosses the network and passes through routers, the layer 2 addresses change at each hop (since you’re dealing with a new link each time), but the layer 3 addresses stay the same throughout the journey.
Layer 1 – Physical
The physical layer deals with the actual transmission of raw bits over a medium. This includes electrical signals over copper, light pulses over fiber, and radio waves for Wi-Fi. It defines things like pin layouts, voltage levels, frequencies, and encoding — essentially, what a 1 or a 0 looks like on the wire.
Encapsulation and Decapsulation
As data moves down through the layers on the sending side, each layer adds its own header (and sometimes a trailer). This process is called encapsulation. The data gets a little bigger at each step.
On the receiving side, the process is reversed. Data flows up through the layers, and each layer strips off its own header and trailer, passing the result up to the next layer. This is called decapsulation. By the time the data reaches the application layer, it’s back in its original form.
Each layer only communicates with the layer directly above and the layer directly below it. This clean separation is what makes it so easy to mix and match different protocols to achieve different goals.
Example: A Web Browser Requests a Page
Let’s walk through a real example to see how this works in practice. A user opens a web browser and types in a URL. Here’s what happens:
On the client (sending) side:
- The browser uses HTTP to prepare the request. HTTP spans the upper layers — for exam purposes it’s considered an application layer protocol, though in practice it touches a few layers.
- At the transport layer, TCP takes over. It assigns a destination port of 80 (HTTP) and a randomly chosen source port. These are added as a header. TCP also stores this session information in memory so it knows which application to pass the response to later.
- At the network layer, IP adds a header with the server’s IP address as the destination and the client’s IP address as the source. The data is now a packet.
- At the data link layer, the client and server are on different networks, so the packet can’t go directly to the server. It goes to the router first. Ethernet creates a header with the router’s MAC address as the destination and the client’s MAC address as the source. A CRC error-checking trailer is added. The data is now a frame.
- At the physical layer, the frame is converted into bits and transmitted over the cable.
Through the network:
The frame passes through any switches without modification (switches operate at layer 2 and just forward frames). When it reaches the router, the router strips the layer 2 header and trailer, reads the IP address, then creates a new layer 2 header — this time with the server’s MAC address as the destination and the router’s own MAC as the source. New error-checking information is also generated.
On the server (receiving) side:
- At the physical layer, the server’s NIC receives the electrical signals.
- At the data link layer, the server checks the CRC trailer for errors. If all is good, it strips the layer 2 header and trailer.
- At the network layer, the server checks the destination IP — it’s its own address. It stores the source and destination IPs in memory for the reply, then strips the layer 3 header.
- At the transport layer, the server reads the destination port: 80. It knows that port 80 is used by its web server software, so it passes the data there.
- The web server application processes the request and sends a response — going through the same process in reverse.
Resources
Try out your understanding with the Understanding OSI quiz!
