What is the OSI and what is it used for?
The Open Systems Interconnection Reference Model was published by the ISO (International Standards Organisation) as well as the Telecommunications Standardization Sector of the International Telecommunication Union. Even though it is the TCP/IP reference model that is widely in use today, the OSI model is the one which is considered as the foundation of the communication networks. There are 7 layers in the OSI reference model- which we will explain in more detail below.
The 7 layers are as follows, remember 1 is the lowest and 7 is the highest.
7. Application Layer
6. Presentation Layer
5. Session Layer
4. Transport Layer
3. Network Layer
2. Data Link Layer
1. Physical Layer
How do I remember all those layers?
The easiest way to remember the order of the layers from the lowest (Physical) to the highest (Application) is the saying "People Don't Need Those Stupid Packets Anyway".
Below is a diagram of how layers interact with each other:
A horizontal communication is denoted as virtual, because it takes place indirectly via a longer vertical communication. For example, the application layer receives a text message from user which is to be sent to the application layer of another host. So, for the two application layers to communicate horizontally, the first application layer has to wrap the message with headers and other information for the next layer in vertical communication, the presentation layer. The presentation layer again wraps the message with its own headers and sends it to the below layer. This process continues till the Physical Layer, which adds error detection and correction bits and sends it over to the physical layer of the receiving host via a medium like optical fibres, cables etc. Now, the physical layer unwraps the extra information from the first physical layer and sends it upwards. Next, the data-link layer removes the header information from its corresponding horizontal layer, the data-link layer of the sending host, and sends the further unwrapped message to network layer. This process continues till the final message is completely unwrapped for the application layer and can be viewed by the user of the receiving host. This wrapping and unwrapping of messages over each communication layer is important to ensure security, reliability, adherence to protocols etc.
Application Layer
The application layer is the layer which directly interfaces with user view of applications. It is the topmost layer in the reference model stack. Some of the common protocols in application layer include FTP - File Transfer Protocol - for transferring files over the network, SMTP - Simple Mail Transfer Protocol - for email services.
Presentation Layer
This layer manages and defines the structure and format of the data that is being transferred from the application layer. It performs translation tasks such as the different types of data used, their encoding, etc.
Session Layer
This layer is used to manage sessions of an application. A session is like a connection between applications on different hosts.
Transport Layer
The transport layer ensures end-to-end connection between two hosts and guarantees error free and lossless data transfer. Some very popular protocols in the transport layer include UDP (User Data Protocol) which is connection-less, unreliable and fast, as well as TCP (Transmission Control Protocol) which is connection-oriented and reliable.
Network Layer
The network layer is responsible for routing and flow control tasks. Internet Protocol, a widely popular protocol for flow control defines the various aspects of network layer.
Data Link Layer
This layer ensures that the data transfer is error free by providing various error detection and correction schemes. Usually the stream of bits and bytes is injected with some redundant error correction / detection bits.
Physical Layer
This is the lowest level layer in the network reference model. It is also known as the hardware layer. It is responsible for transmitting raw bits and bytes across physical media like optical fibres, cables etc. It also performs data encoding and bit synchronization functions.