OSI Model

Before understanding the OSI layers, first understand why layers exist.

When you open a website, many things happen:

If one system had to handle everything together, networking would become very hard to understand and debug.

So networking is divided into layers.

Each layer has one responsibility.


What is the OSI Model?

The OSI Model is a conceptual model used to understand how network communication works.

It has 7 layers:

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

The easiest way to read it:


Layer 7: Application Layer

The Application Layer is where network applications communicate.

It defines what kind of message is being sent.

Examples:

Example:

When your browser sends this request:

GET /users HTTP/1.1

that is Application Layer data.


Layer 6: Presentation Layer

The Presentation Layer handles how data is represented.

It deals with:

Example:

If data is encrypted, compressed, or converted into a specific format, that is conceptually a Presentation Layer responsibility.


Layer 5: Session Layer

A session means an ongoing conversation between two systems.

Not just one message.

It is the context that says:

These messages belong to the same communication.

Imagine a video call.

The call has a beginning:

User A starts call with User B

Then many messages flow during the call:

Audio packets
Video packets
Connection checks
State updates

Then the call ends:

User A or User B disconnects

The full call is a session.

The Session Layer concept is about managing that conversation lifecycle:

Important clarification:

A web login session is not exactly the OSI Session Layer.

When a website says "login session", it usually means the server remembers that you are logged in using a cookie, session ID, or token.

That is an application-level idea.

But it is still a useful analogy because both ideas involve remembering context across multiple requests or messages.

So in simple words:

The Session Layer is about managing the lifecycle of a conversation between two systems.


Layer 4: Transport Layer

The Transport Layer handles end-to-end communication between applications.

Main protocols:

It deals with:

Example:

HTTP usually uses TCP because web data should arrive correctly and in order.


Layer 3: Network Layer

The Network Layer moves packets between different networks.

Main protocol:

It deals with:

Example:

Routers use IP addresses to decide where a packet should go next.


Layer 2: Data Link Layer

The Data Link Layer handles communication inside the same local network.

It deals with:

Examples:

Example:

Inside your home Wi-Fi network, devices use MAC addresses for local delivery.


Layer 1: Physical Layer

The Physical Layer sends raw bits over a physical medium.

It deals with:

Example:

Wi-Fi sends data using radio waves. Ethernet sends data using cable signals.


OSI Model Summary

Layer Name Responsibility
7 Application Application protocols like HTTP and DNS
6 Presentation Encoding, compression, encryption, data format
5 Session Start, maintain, and close sessions
4 Transport End-to-end delivery using TCP or UDP
3 Network IP addressing and routing
2 Data Link MAC addresses and local network delivery
1 Physical Raw bits over wire, radio, or fiber

Interview Answer

If an interviewer asks:

Explain the OSI model.

You can answer:

The OSI model is a 7-layer conceptual model used to understand network communication. The layers are Physical, Data Link, Network, Transport, Session, Presentation, and Application. Physical sends raw bits, Data Link handles local delivery using MAC addresses, Network handles IP addressing and routing, Transport handles end-to-end delivery using TCP or UDP, Session manages sessions, Presentation handles encoding, encryption, and data format, and Application contains protocols like HTTP and DNS.