Fundamentals 16 min read

Understanding the OSI and TCP/IP Network Layer Models

This article explains the OSI seven‑layer model and the TCP/IP four‑layer model, describing each layer's responsibilities, protocols, and a step‑by‑step example of how an email travels from the application layer down to the physical medium and back.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Understanding the OSI and TCP/IP Network Layer Models

1. OSI Network Layer Model

1.1 Protocol Layering

In the OSI model each layer receives services from the layer below and provides services to the layer above; the contract between adjacent layers is called an interface, while the contract within the same layer is called a protocol.

1.2 OSI Reference Model

Layer 7 – Application: Provides services to applications (e.g., file transfer, email, remote login).

Layer 6 – Presentation: Transforms data into a network‑compatible format and vice‑versa.

Layer 5 – Session: Manages connections, session establishment, termination, and data segmentation.

Layer 4 – Transport: Ensures reliable end‑to‑end data transfer.

Layer 3 – Network: Handles addressing and routing of packets to their destination.

Layer 2 – Data Link: Frames raw bits into meaningful data units for transmission over the physical medium.

Layer 1 – Physical: Converts bits into electrical/optical signals for the transmission medium.

1.3 OSI Communication Example

The sender processes data from layer 7 down to layer 1, adding a header at each layer; the receiver processes the packet from layer 1 up to layer 7, stripping headers and finally delivering the original message to the application.

Application Layer Example (Sending an "Good morning" email)

The application layer attaches a header indicating the message content and recipient before passing the data to the host’s mail client.

Presentation Layer

It converts data between the application’s format and a network‑compatible format, adding its own header if needed.

Session Layer

Manages connection establishment, termination, and ordering of multiple messages; it also adds a header describing transmission order.

Transport Layer

Creates a logical connection, ensures reliable delivery, and may retransmit lost data.

Network Layer

Routes the packet toward the destination across multiple networks.

Data Link & Physical Layers

The data link layer frames bits for transmission; the physical layer converts bits into electrical/optical signals.

2. TCP/IP Network Layer Model

2.1 Comparison with OSI

The TCP/IP model condenses the seven OSI layers into four: Network Interface (Link), Internet (Network), Transport, and Application.

Network Interface Layer

Handles raw packet transmission over Ethernet, Wi‑Fi, etc., using MAC addresses.

Internet Layer

Implements the IP protocol for routing packets based on IP addresses.

Routers operate at this layer to forward packets.

IP

IP provides global addressing and packet forwarding but does not guarantee delivery (non‑reliable).

ICMP

Used for error reporting and network diagnostics.

ARP

Maps IP addresses to MAC addresses.

Transport Layer

Provides end‑to‑end communication using ports; TCP offers reliable, ordered delivery, while UDP is connectionless and unordered.

Application Layer

Hosts protocols such as HTTP, SMTP, FTP, SSH, etc.

2.2 TCP/IP Communication Example

Packet Header Construction

Each layer adds its own header containing addressing and protocol information.

Data Transmission Process

When user A sends an email to user B, the application creates a TCP connection, adds a TCP header (source/destination ports, sequence number, checksum), which is then encapsulated in an IP header (source/destination IPs) and finally in an Ethernet frame (MAC addresses) before being sent over the physical medium.

Network Interface Handling

The NIC adds an Ethernet header and forwards the frame to the physical layer.

Physical Layer Transmission

Bits are converted to voltage or light pulses and transmitted.

Reception Process

Network Interface

The NIC checks the Ethernet header; if the MAC address matches, it passes the payload to the IP layer.

IP Layer

The IP layer verifies the destination IP, then forwards the payload to the appropriate transport protocol (TCP/UDP).

TCP Layer

TCP validates the checksum, reassembles segments based on sequence numbers, and acknowledges receipt.

Application Layer

The receiving application finally obtains the original email content.

protocolsTCP/IPOSI modelnetwork layersnetworking fundamentals
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.