OSI model layers explanation  and Functions


Before explaining layers in the OSI model, we need to know what the OSI means and where it comes from.

The OSI full form is Open Systems Interconnection. In communication, an open system means that any device can communicate with other devices by using standard message formats and procedures.

OSI model is a reference model developed by the International Organization for Standardization (ISO) to provide guidelines for an open standard for communication. The whole model is divided into seven layers.

It does not mention any underlying technologies or any other specific protocol for implementation. This is a suggested framework to which an actual implementation can refer. In this OSI model tutorial, we will cover the following functions of each OSI model layer.

  1. What is a layer?
  2. What is a Layered Architecture? 
  3. Peer to Peer communication.
  4. Layer addressing in the OSI model.
  5. What is the Physical Layer?
  6. What is the Data Link Layer?
  7. What is Network Layer?
  8. What is the Transport Layer?
  9. What is the session layer? 
  10. What is the presentation layer? 
  11. What is the application layer?
  12. Example Message Flow

Why are there layers in the OSI Model?

There are two essential building blocks of the OSI model. First, the model is based on layered architecture, and in another, there are primitives between the layers for communication. The primitives could be based on function calls or message passing. The former is called tightly coupled, while the latter is loosely coupled. 

What is a layer in the OSI model? A layer is an independent entity that implements a fixed set of functionalities. A layer provides services to the upper Layer and uses the services of the lower Layer. The upper Layer is a service user, while the lower Layer is a service provider.

What are primitives? Communication between the layers is defined in terms of primitives. E.g., a transport layer sends the message when there is a send data request from its user. This means the send request is a primitive of the transport layer.

In a layered architecture, a  layer provides services to the user of the Layer and uses services from another layer. There can be multiple users and multiple service providers for the same Layer. 

Layers can be loosely coupled or tightly coupled

In a loosely coupled system, communication between layers is message-based. 

In tightly coupled, communication between layers is function-based. This means if layer 2 wants to use the functionality of layer 1, then it will directly invoke the primitive function in layer 1.

Layers In the OSI Model

There are seven logical layers in the OSI model. Or you can say logical demarcation of functionalities for achieving computer network communication. Each Layer defines a set of functionalities. In actual implementation, the actual protocol stack implementation for communication may break a layer into several independent layers, or it can combine multiple layers into a single layer.

Layers in OSI model
Layers in the OSI model

Peer-to-peer Communication in OSI Model:

First, we will explain what peer-to-peer communication is. What is a peer in the OSI model? A peer is a remote layer at the same level, for example. The transport layer of the remote protocol stack is the peer of the local transport layer. When a local peer sends a message to the remote, it adds its address and peer address in the header. For the lower Layer, the header is user data only. The remote peer uses the header to handle the message.

Addressing In OSI Model:

For communication, addressing is mandatory. Mainly in case the remote application is not present on the local machine. In the OSI reference model, until Layer Four, there is an address for each Layer. For the upper layers, there is no address. The address format depends on the actual protocol implementation and underlying technologies.

PDU in the OSI model:

Protocol data unit or PDU  in networking is the information unit exchange between the two layers. There is a one-to-one relationship between a primitive and protocol data unit.   A PDU contains a header part and the data part. The header part is optional. A PDU has a header and data in the OSI model till layer 4. From layers 4 to 7, there is only user data.

protocol data unit in networking
protocol data unit in networking

A header may contain the following parts:

  1. Source Address, this is the address of the sending Layer.
  2. The Destination Address is the address of the peer layer.
  3. Control Flags are the information present in the header for controlling the behavior of the message over the network. For example, a flag may convey the message is a management message, not the user data message. So that the receiving peer layer process the message locally. Do not transfer messages to the upper Layer.

Physical Layer:

This is the lowest Layer in the OSI model. The functionality of this Layer is to communicate with the peer physical layer over a wired/wireless. Physical media understand electrical signals in 0 and 1 format. Zero means low current, and 1 means high current. For example,  if one end wants to send a byte value 0x56. Its binary equivalent will be 01010110. There will be low, high, high, low, high, low, high, and low the sequence for electric current. There will be a separate details tutorial for the Physical Layer.

Data Link: 

The second Layer is the OSI model. It provides error-free and in-sequence delivery of frames between directly contented machines. The data link layer has two sub-layers.

  • MAC or Medium Access Control

  • LLC or Logical Link Control

The details of the Layer are explained in a separate tutorial.

Network Layer:

The third Layer is the OSI model. It does the routing of packets received from the upper Layer. The upper Layer is the user of the Network Layer. In the OSI model, the user is the transport layer. The routing is end-to-end. What does end-to-end mean? This means the source to the destination IP layer.

Multiple IP layers can be in the path from source to destination nodes. For the layers in the path, check if the packet destination address is the address of the current IP layer or Host. If yes, the Layer sends the packet to the user or forwards it to the next hope for further routing. 

For example, if you are browsing yahoo.com. Then the source IP layer is in your Computer or Laptop, and the destination is on the Yahoo server.

The intermediate IP layers are in the router you are connected to via the LAN cable of WiFi and in the ISP network.

Transport Layer:

Fourth Layer In the OSI model. Responsible for delivering user messages to the destination. The destination is the user of the peer transport layer user. It also does end-to-end routing. So only end node transport will receive the message. The message will be routed from the network layer only on intermediate nodes. The Layer also does error correction and sequencing. SCTP protocol is an example of transport layer implementation.

Session Layer:

Fifth Layer in the OSI model. A session is a logical connection with the peer. The same session layer may have multiple sessions with a remote peer. A session is useful for correlating requests and responses. For example, the HTTP protocol uses a session.

If a response comes and there is no session, the response is dropped. Why is the session layer needed? User layer can not do the session management? The answer is yes. The user layer can do this. But like other layers, this functionality saves session or dialogue control time and errors.

Presentation Layer:

A computer network runs with multiple computers with different machine architectures. A computer may be a big-endian or little-endian etc. It is not only the machine, but other factors also exist, like character set, etc. The presentation layer converts from the local application to the network format and vice versa. It does the user application layer’s data encryption, translation, and compression.

Application Layer:

As the name suggests, which implements user application logic rather than focusing on data transfer over the network. FTP, SSH, and SCP are a few examples of an application layer. There can be already defined as applications or user-developed new applications.

Example Message Flow In OSI Model tutorial

This section of the OSI model tutorial includes the sample protocol data unit flow. The upper three layers don’t have a specific header for routing. Following is the flow from layer 4.

Transport Layer Add its header in user data. User data is the data from the Session Layer.

Flow sender side:

OSI model example message flow
OSI model example message flow

Upon receiving primitives from the transport layer. The network layer adds its header to the data received from the transport layer.

Network User (NU)- Data = Transport header + session data.

Network layers issue the primitive to the data link layer. The Data Link layer adds its header to the data from Network Layer.

Data Link User (DU)- Data = Network header + Transport header + session data.

Data Link uses the service of the Physical Layer. The physical layer adds its information and sends a message to the peer physical layer.

Flow receiver side:

On the receiving side, actions are opposite as compared to the sender.

The physical layer removes the header and sends the renaming data to the Data Link.

Data Link removes the data-link header and sends the remaining data to the network layer.

Network Layer removes the header and sends the remaining data to the transport layer.

The transport layer removes its header and sends the remaining data to the session layer.

Now the other layers transfer to the application layer.

We can see in the example that the receiving OSI application layer got the same data or message initiated by the sender application layer.