Understanding OSI model as a software engineer 
Published: 2020-11-15 17:48:06

OSI model: (Open System Interconnection) is a 7 layered architecture model that is standardised in the communication system.

Here are the 7 different layers:
1. Physical layer
2. Data link layer
3. Network layer
4. Transport layer
5. Session layer
6. Presentation layer
7. Application layer

To understand the OSI model let us a consider a scenario where we are in a private network, within the network one of the machine has a webserver running on it. One more machine in the network wants to  do a get request to the webserver.


Working of OSI model on sender side:
• As the sender is going to do a get request in our scenario we will have the Http headers. Building the http headers is the job of an Application layer.
• If you want the above request to be encrypted, Presentation layer will encrypt the data for you. It means it is going to be a Https request.
• As we are using the connection based architecture, we want the communication to be stateful for that purpose Session layer appends a session id to the object that we received from presentation layer.
• From session layer we actually received a series of encrypted bits, Transport layer actually divides the object into some manageable segments. Where each segment is appended with source and destination port numbers because we deal with port numbers in sending the data.
• Now to the each segment that we received, where all the segments packed are under one object. Network layer  appends source IP and destination IP to each of the segment
• The segment's we received from network layer will be further divided into small frames by Data link layer and it also performs a reverse engineering technique where it tries to derive the Mac address from the destination IP and appends them on to the Frames
• All the Frames are converted into ones and zeros by the Physical Layer which will be used as electric signals, light signals or WiFi signals



*Working the OSI model on the receiver side*:
• Now let's assume the signals are received at the receiver side then our receiver try to convert the signals to data frames and reads the Mac address from first frame. If the Mac address on the network card  matches with  Mac address from dataframe then the object will be sent to network layer. If Mac address  doesn't match the object will be dropped by the network card.
• At network layer the destination IP address will be read and if it matches then it will be processed to session layer
• From the session layer session id is read and sends the object to Presentation layer
•  At the presentation layer all the encrypted data be decrypted and sent to application layer
• Finally at the application layer the http headers will be read and does the necessary processing and sends the response 



So this is how it works. Here I tried to explain everything at a very high level but a networking person can explain way deeper by talking various things like  address resolution protocol and sliding window protocol and lot more. But as software engineer having a basic idea of OSI model is really helpful.


Thank you for taking time to read this blog.
If any thing is wrong with explanation please correct them in comments section.

I'm learning and trying to get better at things 😊 So your suggestions are really appreciated.

Thank you again!!!


Credits goes to Hussein Nasser