top of page
Programming

What is OSI Model? 7 layers of the OSI Model Explained (2023)

Updated: Dec 9, 2022



Imagine you are on your computer and you want to send an image to your friend who is on a different computer. You can use a wire and connect both computers to transfer this image. But wait! There are some problems with this. How do you guarantee that the computer which your friend has can make sense of the data which is being sent to him? The cable will send data in the form of electric signals (0s and 1s). You need to follow a set of rules to convert your file data to a transferable form of 0s and 1s. Your friend's computer would also need to follow the same set of rules to recreate the image from the received binary data. This set of rules is what the OSI Model is all about.


You might be wondering - "Hey Gourav, Why did you include this in your Backend Development Series? We don't care about the OSI model in the backend. The OSI model is all about computer networks". Well, you are partly correct. As a software developer or software architect, there are actually situations where you can implement certain parts of code or design your system in a better way if you are aware of the underlying technology and how things work in computer networks, even though you do not actually use these inner details. So if you are someone who is a software developer or a computer networks engineer or someone who wants to know about about the OSI model, this blog is for you.

So, let's dive right in -


1. What is the OSI Model?

OSI Model in computer networks

OSI stands for Open Systems Interconnection. It can be defined as a conceptual framework that maps the various functions of a communication system in seven layers. The International Organization for Standardization (ISO) defines these layers and what each layer does. In layman's terms, the OSI model basically ensures that different computer systems send information to each other in a standardized way. Once you learn the OSI model, you will be able to relate to and appreciate more how the Internet works.


2. Who Developed The OSI Model?

The OSI (or Open Systems Interconnection) model was invented in 1984 by the International Standardization Organization - ISO and contains 7 layers namely- The physical layer, Data Link layer, Network layer, Transport layer, Session layer, Presentation layer, and Application layer.


Each layer can have its own set of protocols. The OSI (or Open Systems Interconnection) model is an industry effort that aims to get participants in the industry (hosting vendors, ISPs, and even individuals) to agree on common network standards. Luckily, this standardization also means that there is a higher chance of seamless interoperability across different vendors' networks - which helps everyone!



3. The 7 layers of the OSI Model Explained

OSI Model 7-layered Architecture


What is a layer?

A layer can be thought of as a logical way of grouping behaviors of the network. In the OSI model, the layers are organized from the least physical or tangible to the most tangible form.

Every layer actually comprises a set of protocols that help to ensure standardization while data transferring.


Just to be clear, the OSI model is the conceptualization of how communication should happen, and not the actual strict rules. As mentioned, the OSI model consists of 7 layers. Let's look at them one by one as to how data flows through the OSI Model.


Spoiler Alert! These are the 7 layers of the OSI model.



I will start with the topmost layer, the application layer.


OSI Model Layer 7: Application Layer


Few protocols used by the application layer
Few protocols used by the application layer

As the name suggests, the application layer is used by computer applications that require communication over the internet. Some examples of these applications would include

Browsers like - Google Chrome, Firefox, Opera, etc., or Video Chat applications like Zoom, Google Meet, etc. Social Media applications like Facebook, Twitter, etc.


These applications use the protocols which belong to the Application Layer. For example, they use protocols like HTTP/HTTPS to surf the internet. HTTP/HTTPS is just one example. There are so many protocols like Telnet, POP3, FTP, DHCP, NNTP, SMTP, and SSH. All these protocols together comprise the Application Layer.


The above-mentioned protocols form the basis of many services which are utilized by these applications. For example

  • HTTP/HTTPS (Hypertext Transfer Protocol / Secure) - Used for browsing the web. Mostly used by web browsers.

  • FTP (File Transfer Protocol): Used for transferring files

  • SMTP (Simple Mail Transfer Protocol) / POP3: Used for sending emails

  • Telnet: Facilitates the option to virtually access someone else's system via a command line interface.

  • NNTP (Network News Transfer Protocol ): Used to transfer news and articles among different networks

  • SSH (Secure Shell): To remotely login to other computers.

The above protocols are just a few listed. There are a lot more of them. In short, the application layer comprises these protocols and services which can be used by computer applications to communicate over the network and the internet.


OSI Model Layer 6: Presentation Layer


Presentation Layer
TLDR: Presentation Layer

This is the second layer from the top of the OSI model. The data from the application layer is sent to the presentation layer. At this point, the data is in the form of alphabets and numbers. The presentation layer converts this set of alphabets and numbers to machine understandable binary number system (0s and 1s). This process is called translation.


Basically, the data which the presentation layer receives is in ASCII format. It is then converted to EBCDIC format.


ASCII stands for American Standard Code for Information Interchange. It's a standard data encoding format
EBCDIC stands for Extended Binary-Coded Decimal Interchange Code. It uses unique 8-bit binary code for number alphabet and punctuation mark.

The presentation layer is also responsible for the data compression of this binary data. Data compression is basically a way to reduce the size of data. This data compression can be either lossy or lossless based on the configuration.


How is data compression useful? If the data is of lesser size, it would mean less time to transfer the data. Hence a more efficient system.


The presentation layer also encrypts the data. The SSL (Secure Sockets Layer) or TLS (Transport Layer Security) encryption that you may have heard about happens in this layer. Both of these are cryptographic protocols responsible for encrypting the data and making it less vulnerable to attackers. The TLS protocol is a successor and improved version of the SSL.


Now since the data is encrypted on the sender side, on the receiver side, the presentation layer will decrypt the data so that the receiver can view the message which was originally sent. So the Presentation Layer is also responsible for decrypting the data when new data is received.


In short, the presentation layer is responsible for the following:

  • Translation

  • Data Compression

  • Encryption or Decryption


OSI Model Layer 5: Session Layer

Session Layer
Session Layer

The session layer is responsible for the management of the data being sent. Basically is responsible for establishing connections with the sender/receiver, maintaining this connection, and terminating it.

It can be thought of as a client/server model - when the client performs any operation, the server authenticates the client to check that the client is a valid user. When the client makes a request, the server authorizes the client to have access to the resource it requesting.

For eg, the client may request a video. The server will then check that the client has the required permissions to access that video.

This authentication and authorization happen in the session layer.


This session of request and response can happen for a short time or a long time, it can be single-directional or bi-directional communication.


The HTTP/HTTPS APIs are generally single-directional, whereas WebSockets are bi-directional.


To know more about WebSockets, checkout my blog on websockets: https://www.thegeekyminds.com/post/all-about-websockets

For reading about good API design practices, checkout : https://www.thegeekyminds.com/post/apis-and-how-to-design-them-all-you-need-to-know

The session layer is also responsible for keeping a track of the past data which was sent or received and mapping them with the appropriate requesters. For example, your browser requested a pdf from the server. The pdf will be received in the form of data packets. The session layer is responsible for keeping a track of which data packets belong to the pdf and returns the appropriate data to the browser which requested it.


Examples of protocols for the session layer include APIs (Application Programming Interface), NetBIOS (Network Basic Input Output System), RPC (Remote Procedure Call Protocol), etc.


OSI Model Layer 4: Transport Layer

TLDR: Transport Layer
TLDR: Transport Layer

The transport layer controls the reliability of communication and data transfer. Let's see how this happens.


This layer is responsible for data packet segmentation. Data received from the session layer is divided into smaller data units. These data units are called segments. Each segment contains a source and destination port number, and a sequence number. Various applications listen at different ports. So the port number helps to direct these segments to the appropriate application. The sequence number is used for rearranging data in the correct order so that the original message can be reconstructed at the receiver.


Flow control is another important aspect of the transport layer. It controls the amount of data being transmitted and the order in which it is sent. By "controls the amount of data", I mean the speed of data transmission. Let's say the receiver cannot receive data at a speed of more than 10 Mbps, the transport layer of the receiver will communicate this information to the transport layer of the sender, and the sender will try to send data at the same speed of 10Mbps.


The transport layer is also responsible for error control. For example, if a segment or data unit got corrupted while transmission, the transport layer of the receiver can re-request for that particular segment and it will be retransmitted.


The method of checksum is used to identify and validate whether any packet is missing or not.


The 2 main protocols of the transport layer are TCP and UDP.

  • TCP (Transmission Control Protocol): The data unit or segment of TCP is called a packet. The TCP protocol prioritizes data quality and reliability over speed using its handshake mechanism.

  • UDP (User Datagram Protocol): The data unit or segment in UDP is called a datagram. The UDP prioritizes speed over data quality. It does not require a handshake.

Since UDP does not require a handshake, it is faster than the TCP protocol. Since TCP makes use of feedback (handshake) the corrupted packets are re-sent in TCP. Since UDP does not require a handshake, it is called connectionless transmission. TCP is known as connection-oriented transmission.


UDP is used in places like online games and online video streams where we don't care if every packet has been received.

TCP is used in places where it is necessary to deliver full data - for eg. browsing the internet, downloading a pdf, etc.


The transport layer sends these segments to the network layer.