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
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
FTP (File Transfer Protocol): Used for transferring files
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
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.
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:
Encryption or Decryption
OSI Model Layer 5: 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.
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
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.
OSI Model Layer 3: Network Layer
The network layer is responsible for sending the above-created segments across different networks. The network layer comprises routers.
The routers in the network layer are responsible for IP addressing and storing the information in the routing tables. The network layer attaches the sender IP and receiver IP to the segments and forms packets. The IP addresses follow either IPv4 or IPv6 protocol. Once a computer is connected to the internet or any network, it is assigned this IP address.
The IPv4 address looks something like this: 220.127.116.11
The IPv6 address looks something like this: 684D:1111:222:3333:4444:5555:6:77
Let's say I request the server for certain information. When the server responds back with the information, it needs to know where to send the data. This destination address is denoted by IP address which is unique to everyone. The router in the network layer makes sure to deliver this data to the correct receiver. Since the packet already has the sender and receiver IP addresses, the router will know where to send the packet.
The router in the network layer is also responsible for choosing the best possible path to send the data. Some of the protocols they use for this are - OSPF (Open Shortest Path First), BGP (Border Gateway Protocol), IS-IS (Intermediate System - Intermediate System), etc. to determine the best possible path.
The network layer connects to the ISPs (Internet Service Providers) to connect to the internet.
OSI Model Layer 2: Data Link Layer
The packets from the network layer are received by the data link layer. Each computer/machine along with its IP address also contains a physical address called the MAC (Media Access Control) address. A MAC address is a unique address assigned to a physical network interface card. No 2 network cards in the world have the same MAC address. A typical MAC address looks like this 00:00:4d:00:42:af.
The source and destination MAC addresses are attached to the network packet received from the network layer. The new data unit formed is called a frame.
The network interface media is actually connected to a physical wire like copper wire or an ethernet cable or to wifi to transfer these frames.
The Data Link Layer is responsible to get the frames from the above-mentioned media (like wireless or via cables). This is called Media Access Control.
Error detection is also another task that is carried out here. The tail of each frame contains certain bits which have the error detection information. In case errors are detected, the frames are rejected and the error may be reported to higher layers depending on the configuration. These errors may occur due to certain physical limitations in the media.
The frames here look like a sequence of 0s and 1s. "000110101010101"
OSI Model Layer 1: Physical Layer
The final layer is the physical layer. Until now we have converted the data into the frame by segmenting, encrypting, and appending the source and destination IPs and MAC address. The final data looks like a sequence of 0s and 1s called bits.
The physical layer is responsible for transmitting these bits over the medium. The bits are converted to
Electric signal in the case of copper wires or ethernet cable
Light signal in case of optical fiber
Radio waves (802.11 WiFi, a/b/g/n/ac/ax variants, or Bluetooth) in case of air.
Now that you know what each of the 7 layers is responsible for. Here is a diagram of how the data actually travels from the sender to the receiver.
4. Comparison of the OSI model to the TCP/IP model
OSI vs TCP/IP
The OSI model is a layered model that defines how data should be transmitted between two endpoints or nodes. The TCP/IP model is a protocol suite that defines the standards for how data should be transmitted over the internet.
The OSI Model is also known as the Open Systems Interconnection (OSI) model. It was created by ISO and IEC to help standardize network protocols in the 1980s. The TCP/IP Protocol Suite, or Transmission Control Protocol (TCP) and Internet Protocol (IP), was designed by ARPA in 1977.
The OSI Model has seven layers: Physical, Data Link, Network, Transport, Session, Presentation, and Application. The TCP/IP Protocol Suite has four layers: Network Interface Layer (NIL), Internet Layer (IL), Transport Layer (TL), and Application Layer (AL).
These are the high-level differences. To know more about it, refer to this site.
5. How to remember the OSI Model 7 layers – Mnemonic tricks
Application to Physical (Layer 7 to Layer 1):
All People Seem To Need Data Processing
All: Application Layer
People: Presentation Layer
Seem: Session Layer
To: Transport Layer
Need: Network Layer
Data: Data Link Layer
Processing: Physical Layer
6. My thoughts and Conclusion - Why does the OSI model matter?
Does the OSI model remain relevant? Why do you need to know about the 7 OSI layers?
Although the modern Internet doesn’t strictly follow the OSI Model, it does adopt its principles. The OSI Model is still very useful for fixing network problems, as it is based on a fixed architecture. One of the simplest and most effective ways to examine a problem is by using the OSI Model. If the issue can be narrowed down to one specific layer of the model, then we won't have to go through so many steps. Problems related to the internet not working or the server being down for so many people.
Now that you know all about the OSI model, drop a comment if you liked this blog.
And that's a wrap! Hi, I am Gourav Dhar, a software developer and I write blogs on Backend Development and System Design. Subscribe to my Newsletter and learn something new every week - https://thegeekyminds.com/subscribe