OSI Model Demystified for The Curios Mind.

Shyam Sreenivasan
6 min readJan 3, 2024

--

Photo by Sergey Zolkin on Unsplash

How do two computers really talk!!! What’s happening in all those mysterious OSI Layers.

For the uninitiated, we come across 7 Layers of OSI (Open Systems Interconnection) when dealing with computer networks.

  1. Physical Layer
  2. Data Link Layer
  3. Network Layer
  4. Transport Layer
  5. Session Layer
  6. Presentation Layer
  7. Application Layer.

Let’s get to it in a moment. But for now, think about a nice gift you want to send to a friend, may be a lover.

Now you wrap the gift inside a box, inside a box, inside a box, inside a box…then send it to the friend across the city,

And then on the other end your friend unwraps the box, then the one inside, then the one inside that and so on, until he finds the actual gift deep down.

Much like this gift, let’s say we want to send a message to a friend from our computer, across the internet.

The message goes through various layers mentioned above and gets prepared by your computer before it can be sent across. And why?? Let’s find out!!

Let’s start with what computers understand. Bits. A sequence of 0s and 1s.

In order to exchange data between any 2 systems, you need a physical medium such as wires or optic fiber cables.

This represents the physical layer. In a physical layer, raw “bits” are exchanged.

Let’s say you want to send the message “Hi” to a friend over a computer network. Then you will send 01101000 01101001 which corresponds to the binary representation of “Hi”, via the physical connection.

That’s the simplest way to exchange info between 2 systems.

And that’s how the physical layer was born!!

Hold on!!

  • The physical layer can be unreliable and
  • the bits can be corrupted, received more or less than what was sent depending on physical conditions like electromagnetic fluctuations.
  • and what if the sender sends other kinds of messages like hello, bye, cool, etc. or a combination of them continuously?

The receiver will either receive corrupted data or will receive data that is completely junk or gibberish to the receiver.

How do you detect that and resolve it?

You agree upon a predefined format of the data you want to exchange.

So, your data format contains more than just your “Hi” message.

  • you add a stream of marker bits before the actual data to say, “this is the start of the sequence”.
  • Similarly, you will attach an end sequence of bits to say, “this is the end of sequence”.
  • You will then repeat the same message a few times (redundancy) and add checksums to make sure that even if the data gets corrupted, it can be detected and recovered at the receiver end.

This entire sequence, start markers, data bits, error codes, end markers, together is called a frame.

A frame is more than just 01101000 01101001 which corresponds to the message “Hi”. You will include other bits as well in the sequence

<start marker> <message> <error codes> <end marker>

Which may now look like,

0101001000001101000 0110100110101001010

Data link layer exchanges “frames”.

Okay great. Now we have reliable communication. Thanks to the data link layer.

But this is good only if 2 devices are “directly connected to each other”.

Sender sends data directly to the receiver through a single direct medium like a wire.

What if the 2 systems (hosts) are not directly connected?

In a real-world scenario, 2 hosts can be connected indirectly via routers. Well, they may be very far apart, like even in two different countries.

Now if A tries to send a message to B, it can send only to the immediately connected router and not B directly. The router needs to know how to forward the data so that it reaches B.

So additional information is added to the “message” to successfully route data to the receiver. The additional info is.

  • “Who is the sender”,
  • “Who is the receiver”

and other necessary details.

Who is who in the computer world is determined by an address.

IP address of each host.

It is again nothing but a sequence of bits to identify a host. You can imagine the name of the pc “Shyam-PC” as the address. (In the real world, IP addresses look different, something like 10.12.124.123).

All of this info together is called a “packet”.

Now the router knows how to forward the packet to the destination using a “forwarding table”, which is nothing but a mapping of the sequence of paths to reach a destination, thanks to the packet information.

The network layer transports “packets”.

Great. Now, data can be transferred between any 2 computers that are not directly connected. Isn’t that amazing!!!

Thanks to the network layer which adds necessary sender, receiver addresses.

But wait, any 2 systems can exchange various kinds of unrelated information. Imagine running a messaging app like WhatsApp and another application for sending and receiving emails like Gmail.

When the packets are received by the destination host B, how does it know to which application the sequence of bits belong to. (text message or email)

This is where the transport layer enhances the data by adding something called "port” which uniquely identify the individual processes that are running on the system. A port is a unique number for each application/process and is simply a value to determine where to deliver the received bits.

Whatsapp application could run on port 5000

Gmail application could run on port 5490

The sender host adds the port information to the data to determine the correct destination application. Now message data arriving at the host correctly goes to the right process/application identified by the port.

This is why when reading about the transport layer, you always see the transport layer enables end-to-end communication.

Transport layer exchanges “segments”

Although the transport layer does more stuffs like connection established, reliable message delivery via synchronous messaging, congestion control, error control and so on, the simple idea is that it is used to identify unique processes in the system that the message is supposed to be delivered to.

Transport layer exchanges segments.

Wonderful. Now the application layer is where the actual user understandable data is created / received.

Also called the Application Data Unit. (ADU)

When sending a message from Computer A to Computer B, say “hi”, the conversion happens this way in each layer.

Message — ADU — segments — packets — frames — bits in Computer A before sending.

A beautifully packed gift by the network stack

In summary,

  • When you send a message called “hi”, it will convert be first into an ADU.
  • The ADU is enhanced with port number and other details and is called a segment.
  • The segment is encapsulated with source and destination IP addresses and is called a packet.
  • The packet is encapsulated with more information about marker bits and error checks to make it a frame.
  • The frame is finally sent over the physical layer as bits.

The OSI model adds more abstraction like security layer and presentation layer, but it’s essentially the same pattern of thinking.

Also, networks use various algorithms for efficiency, reliable delivery, congestion control, scaling, and security. I don’t intend to discuss those here, as the idea behind this write up was to show how data is packed in each layer before transmission.

Thanks for staying with me till the end. Hope this was an insightful one, and something that will stay with you longer. Look forward to more exciting stuffs.

--

--

Shyam Sreenivasan

Development Team Lead. I write about Technology - (programming, system design, software architectures) And Psychology (mental health, habits, productivity)