What is the OSI model and why is it necessary?
What happens when you send a message, let's say, in Telegram? It's clear that Telegram sends the message, but what happens on your computer and in the network at that moment? Where do the files go, and how do they know where to go? Let's figure it out together in this article.
What is the OSI model?
The OSI model (Open Systems Interconnection), or the OSI reference model, describes how devices in local and global networks exchange data and what happens to that data. It was proposed in 1984 by engineers from the International Organization for Standardization (ISO), which was working on a unified standard for data transmission over the Internet.
The OSI model itself is not an internet standard like TCP/IP, for example; it can be compared to frameworks in the world of programming languages. The OSI model provides various web standards "out of the box," including UDP, HTTP, FTP, Telnet, and many others. In total, there are over 100 such protocols.
The OSI model consists of seven layers, and each layer performs a specific function, such as transmitting data or presenting it in a human-readable format on a computer. Interestingly, each layer has its own set of protocols.
Layers don't know anything about how other layers work. This is called abstraction.
The lowest layer is responsible for the physical representation of data, that is, how data is transmitted over wires or using radio waves, while the topmost layer is responsible for how applications interact with the network.
The lower layer operates with concepts such as "cable type" or "connector type," while the upper layer deals with concepts such as HTTP or API.
Let's examine each layer in more detail.
Physical Layer
The first level of the OSI model is the Physical Layer. At the lowest level, data is represented as physical objects—electricity, light, or radio waves. These physical objects are transmitted over wires or through wireless signals.
This layer deals with cables, connectors, signal modulation, encoding of binary digits (0s and 1s), and other low-level components. Essentially, the first layer is concerned with wires and the physical methods of signal transmission. It represents the minimal abstraction level.
The most well-known protocol at the Physical Layer is Ethernet. It describes how signals are encoded and transmitted over wires. In addition to Ethernet, there are also protocols such as Bluetooth, Wi-Fi, and Infrared (IR) that provide instructions for data transmission.
The devices at the Physical Layer include hubs and repeaters. They operate with the physical signal "as is" and do not delve into its logic: when they receive data, they simply pass it along the wire.
Data Link Layer
The second level of the OSI model is the Data Link Layer . It resides above the Physical Layer. Its main tasks are to ensure the integrity of received data and correct errors. This layer is "smarter" than the previous one because it understands that different voltage amplitudes correspond to different bits—zeros, and ones. Additionally, the Data Link Layer can encode signals into bits and transmit them further.
The data received from the lower layer is divided into frames or packets. Each frame consists of control information, such as sender and receiver addresses, as well as the actual data itself.
It can be likened to a postal envelope. On the front side of the envelope, you have the sender's address, and inside, you have the actual letter (in our case, the data).
The front side of the envelope represents the MAC address of the device that sent us the information. The MAC address is used to identify devices on a local network. It consists of 48 or 64 bits and looks something like this:
Another important fact about MAC addresses is that when laptops or smartphones are assembled in factories, they are assigned a specific MAC address, which cannot be changed later. The MAC address of desktop computers is embedded in the network card, so it can only be changed by replacing the network card itself.
Using the `ifconfig` command, you can find the MAC address of your Macbook or Linux computer. In Windows, you can use the `ipconfig` command.
The Data Link Layer is not as simple—it is further divided into two sublayers:
- Logical Link Control (LLC): This sublayer is responsible for interaction with the upper layer, the Network Layer.
- Media Access Control (MAC): This sublayer is responsible for interaction with the lower layer, the Physical Layer.
Devices at the Data Link Layer include switches and bridges. They are used to forward frames to the intended recipients. Some protocols at the Data Link Layer include PPP (Point-to-Point Protocol) and CDP (Cisco Discovery Protocol).
Network Layer
The third level of the OSI model is the network layer. This level is responsible for data routing within the network between computers. Terms such as "routers" and "IP addresses" come into play at this stage.
Routers allow different networks to communicate with each other by using MAC addresses to establish a path from one device to another.
At the network layer, data is represented in the form of packets. These packets are similar to frames at the data link layer but use different sender and receiver addresses—IP addresses.
To obtain the IP addresses of both devices (sender and receiver), the Address Resolution Protocol (ARP) is used. ARP is capable of converting MAC addresses to IP addresses and vice versa.
This is what the packages look likeTransport Layer
The fourth level of the OSI model is the Transport Layer. As the name suggests, this layer is responsible for the transmission of data across the network. Two main protocols exist at this layer: TCP and UDP. They determine how data will be transmitted.
TCP (Transmission Control Protocol) is a protocol that ensures the reliable delivery of data. It meticulously tracks each bit of information but operates at a slower speed compared to UDP.
For example, when you enter your username and password while logging into a social network, it is crucial that all characters are transmitted in a specific sequence. If any characters are lost or altered, you won't be able to authenticate successfully. Therefore, the TCP protocol uses various methods of verification, such as checksums.
This is what TCP is for - so that the data arrives in the correct form.
In the case of video or audio transmission, minor losses are tolerable, while data transfer speed is crucial. This is where the User Datagram Protocol (UDP) comes into play. It no longer verifies the integrity of individual bits but focuses on quickly transmitting data from one device to another.
In the TCP protocol, data is divided into segments. Each segment is a part of a packet. Segments are used to transmit information across the network, taking into account its bandwidth.
For example, if you are sending data from a computer with a bandwidth of 100 Mbps to a smartphone with a bandwidth of 10 Mbps, the data will be divided in a way that avoids the congestion in the slower device.
This is how the data is divided into several segments to squeeze into a network with a bandwidth of 10 Mbps.Segmentation is also important for reliability. A single large packet can be lost or misdirected to the wrong recipient. However, by dividing the data into smaller packets, the risk of such errors is reduced, and it even allows for the verification of their quantity. If a segment fails to be delivered, the TCP protocol can request it again from the sender. This ensures reliability.
In UDP, data is divided into datagrams, which are similar to packets but are autonomous units. Each datagram contains all the necessary information to reach the recipient. As a result, they are independent of the network and can be delivered via different routes and in arbitrary order.
Session layer
The 5th layer of the OSI model is the session layer. From this level and above, data takes on a familiar form, such as JPEG or MP3 files. The goal of the network at these layers is to present information in a human-readable format and allow users to interact with it.
The session layer manages connections or sessions. A typical example is a Skype or Zoom call. When you make a call to another person, a connection is established between your computers, through which audio and video are transmitted. If this connection is severed, your call will be interrupted.
At the session layer, it is crucial for the connection to be properly established and maintained. This means that protocol mechanisms need to verify that both participants have the necessary codecs and that there is a presence of signaling between the devices.
Zoom call sessionPresentation layer
The 6th layer of the OSI model is the presentation layer. At this level, data undergoes transformations such as encoding and compression. For example, received data can be converted into GIF or MP4 files. The same applies in the opposite direction: when a user sends a file to another person, the data is first converted into bits, compressed, and then transmitted to the transport layer.
In addition to encoding and compression at the presentation layer, data can also be encrypted if necessary.
Normal process of sending data from one device to another.Application layer
The seventh and final layer of the OSI model is the application layer. This layer includes network services that facilitate seamless internet browsing.
The application layer can be thought of as a graphical interface for the entire OSI model, enabling users to interact with other layers without even realizing it. This interface is known as the network interface.
The most popular network interfaces include HTTP, HTTPS, FTP, and SMTP. The "devices" at this layer are actually programs such as Zoom, Telegram, and web browsers.
For example, over HTTP, browsers request web pages and receive HTML pages in response.How does the OSI network model work in practice?
At the beginning of the article, we asked ourselves: How are messages transmitted in Telegram? Now it's time to answer that question and show the entire process of data transmission according to the OSI model.
Let's say we want to send a message to our friend. We type the text and click the "Send" button, and then we delve into the inner workings of the computer.
Application Layer: The Telegram application operates at the application layer of the OSI model. When we type a message and click the "Send" button, the data is transmitted to the messenger's server and then to our friend.
The entire process goes through APIs of different libraries, such as those used for HTTP requests. These interfaces facilitate data exchange without delving into the low-level details of how the data is represented. All you need to know is which function to call and what variables to pass.
Presentation Layer: At this layer, the data needs to be transformed into a standardized format that can be transmitted to different devices and operating systems. For example, if we send a message from Windows to macOS, the data must be in a format that is readable by Apple computers. The same applies to other devices.
Since we are going to transmit the data to another computer, it needs to be converted into a binary format. After that, the actual process of network transmission begins.
Session Layer: In order, for the data to be successfully transmitted first to the Telegram server and then to our friend, the application needs to establish a connection or session. This session ensures synchronization between devices and restores the connection if it gets interrupted.
Thanks to sessions, you can see when your conversation partner is typing or sending you images or videos. However, the main purpose of this connection is to provide a stable connection for data transmission.
Transport Layer: Once the connection is established and the data is standardized, it's time to transmit the data. This task falls under the transport layer.
Here, the data is divided into segments, and additional information such as port numbers and checksums is added to them. All this is necessary to ensure that the data reaches the user intact.
Network Layer: Now the data needs to find a route to our friend's device and be sent through it. Therefore, the data is encapsulated into packets and IP addresses are added to them.
To obtain the IP addresses of the devices to which the packets need to be sent, routers (network layer devices) use the Address Resolution Protocol (ARP). This protocol quickly finds the recipient's address and provides it to us.
Data Link Layer: At this layer, the data is transmitted from one MAC address to another. The original text is divided into frames, each containing headers and checksums for data integrity verification.
Physical Layer: At the lowest level, the data is transmitted as electrical signals through wires, cables, or radio waves. The only task here is to respond to signals from above as quickly as possible.
After passing through all the levels of the OSI model, the message is successfully delivered to our friend's device. In reality, this process takes only milliseconds.