The OSI Model and How It Works
Published: 2021-06-24 03:13:28

*In this article, I will go over what the OSI Model is and what each layer does along with its responsibilities.*

### What is the OSI Model? 

The OSI (Open Systems Interconnection) Model is a reference guide to how devices/computers communicate with one another across a network. 

It contains 7 layers. Each layer plays a crucial part in transmitting data across a network. 


### Layers of the OSI Model

![OSI Model and the 7 Layers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/72fyzs9eyhefjcmu5rwu.png)

We will go over each layer and their responsibilities.

**Layer 7: Application Layer**

The application layer is the human-computer interaction layer. This is where the applications accesses the network. 

This would include web browsing, sending emails, file transfers. 


**Layer 6: Presentation Layer**

The presentation layer is responsible for encrypting data (if necessary), data conversion and formatting. This is where you would find file formats like pictures and videos. 

The application may contain lots of data that might not make sense to the rest of the network. This layer takes care of that issue. 

**Layer 5: Session Layer**

An application/program may need to talk to several endpoints. It is important to track where these "conversations" occur. Each conversation is called a *session*. Each session is tagged with a session id as well. 

Ultimately, this layer will create a session between two applications.

**Layer 4: Transport Layer**

The transport layer is responsible for breaking the data down into smaller chunks/blocks. We do not want to send all our data at once if there is a lot of data. Therefore, we break it up into smaller parts. Here, this layer will either use TCP or UDP. 

With TCP, each block is called a data segment. 

With UDP, each block is called a datagram. 

This layer decides how much data is being sent and the rate of which the data is being sent at.

This layer uses port numbers to track where the data is going. Each flow of data has a port number associated with a source and destination host. These values are added to the header for each block of data. 

![PDU Data Fragmentation](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bywzrwtrylkkunt5cktm.png)


**Layer 3: Network Layer**

The network layer is responsible for the routing and where exactly the data will be sent. It adds the source and destination IP addresses and puts that information into another header. 

As of now, the data has two headers (one for ports, the second for IP addresses). This is called a *packet*. 

This layer does not check for errors. Essentially, it blindly sends this packet down to the Data Link Layer.

**Layer 2: Data Link Layer**

This layer is responsible for getting data from once device to another by creating a logical link between devices. 

This layer is comprised of two sub-layers: LLC(Logical Link Control) and MAC(Media Access Control). 

The LLC is responsible for doing the translation between the Network Layer and the Data Link Layer. 

The MAC is responsible for adding headers and trailers to the packet, making it a "frame" now. 

The header will contain the source and destination MAC addresses. 

The trailer will contain information regarding error detection. 

**Layer 1: Physical Layer**

This layer is responsible for converting the frames into bits, encoding the data into physical signals and the actual physical connection between the devices.