Skip to main content

OSI Model

When sending data over a network, a series of transformations, encodings, and actions are necessary for the data to travel from one device to another. The OSI (Open Systems Interconnection) model allows this complex process to be divided into logical steps, called layers, each with a specific role.

Advantages of the OSI Model​

  • Facilitates the design and understanding of networks.
  • Allows interoperability between different manufacturers.
  • Organizes protocols and responsibilities.

Overview of the 7 Layers​

Source: Wikipedia

Layer-by-Layer Detail​

Layer 1 – Physical (Physical Layer)​

Role:
Transmits raw bits (0 and 1) over a physical medium: cable, optical fiber, radio waves...

Functions:

  • Definition of electrical, optical, or radio signals.
  • Bit synchronization.
  • Connectors and cabling.

Examples:

  • Ethernet cable (RJ45)
  • Optical fiber
  • Wi-Fi (at the modulation level)
  • Bluetooth

What does a programmer see? Not much. This layer is entirely managed by hardware.

Role:
Enables local communication between two machines connected to the same physical network.

Functions:

  • Splits data into frames.
  • Assignment and verification of MAC address (Media Access Control, unique for each device).
  • Error detection.

Examples of protocols:

  • Ethernet
  • Wi-Fi (IEEE 802.11)

MAC Address:

  • Unique per network card (e.g., 00:1A:2B:3C:4D:5E)
  • Hardcoded in hardware

Devices:

  • Switch
  • Network Interface Card (NIC)

What does a programmer see? MAC address, frames, local network configuration, sometimes packet manipulation at the Ethernet level (e.g., Wireshark, Scapy).

Layer 3 – Network (Network Layer)​

Role:
Ensures packet routing from one network to another (network interconnection).

Functions:

  • Assignment of IP addresses (Internet Protocol).
  • Routing between subnets.
  • Packet fragmentation.

Examples of protocols:

  • IP (Internet Protocol)
  • ICMP (used by ping)
  • ARP (IP ↔ MAC translation)

Devices:

  • Routers

What does a programmer see? IP address, subnet, ping, communication via sockets (IP/port).


Layer 4 – Transport (Transport Layer)​

Role:
Ensures reliable or unreliable data transport between two machines.

Functions:

  • Segmentation and reassembly.
  • Error control.
  • Flow control.

Main protocols:

  • TCP (Transmission Control Protocol)
    • Reliable, with acknowledgment.
    • E.g., HTTP, FTP, SSH
  • UDP (User Datagram Protocol)
    • Unreliable, fast.
    • E.g., DNS, online video games, VoIP

Ports:

  • Identify applications on a machine (e.g., port 80 for HTTP)

What does a programmer see? Manipulation of TCP/UDP sockets, port management, connection error handling, timeouts, retransmissions, choice between reliability (TCP) and speed (UDP).

Examples:

  • In Python: socket(AF_INET, SOCK_STREAM) (TCP)
  • curl http://... → uses TCP port 80

Layer 5 – Session (Session Layer)​

Role:
Manages communication sessions between two machines. A session is a logical link between two applications.

Functions:

  • Opening, managing, and closing sessions.
  • Restoration after interruption.

Example protocols:

  • NetBIOS
  • RPC (Remote Procedure Call)

Remarks:

  • Not very visible as such in modern applications (often combined with the transport layer).

Layer 6 – Presentation (Presentation Layer)​

Role:
Ensures translation, compression, and encryption of data.

Functions:

  • Format conversion (e.g., plain text ↔ binary).
  • Encoding: ASCII, UTF-8, JPEG
  • SSL/TLS encryption.

Concrete examples:

  • HTTPS = HTTP + TLS (presentation layer)
  • OpenSSL, GnuTLS

What does a programmer see? The presentation layer can be manipulated via libraries like ssl in Python.


Layer 7 – Application​

Role:
Provides network services to user applications.

Protocols:

  • HTTP / HTTPS
  • FTP
  • SMTP / IMAP / POP3
  • DNS

Examples of applications:

  • Web browsers
  • Email clients
  • FTP clients
  • DNS clients

What does a programmer see? You use layer 7 every day: fetch(), requests.get(), socket, etc.

Layer Summary​

N°LayerMain FunctionExamples of Protocols/Devices
7ApplicationUser network interfaceHTTP, FTP, DNS
6PresentationTranslation, encryption, compressionSSL/TLS, ASCII, JPEG
5SessionSession/connection managementNetBIOS, RPC
4TransportReliable transport, segmentationTCP, UDP
3NetworkRouting and logical addressingIP, ICMP
2Data LinkLocal communication, MAC addressEthernet, Wi-Fi (802.11), PPP
1PhysicalBit transmission over the mediumRJ45, Fiber, Radio signal

Example of a Message Journey​

Imagine you are sending an HTTP message to a remote server:

  1. Application (HTTP) → the browser prepares the request.
  2. Presentation (TLS) → the request is encrypted.
  3. Session → a secure session is opened.
  4. Transport (TCP) → the request is split into segments.
  5. Network (IP) → the segments are encapsulated in IP packets.
  6. Data Link (Ethernet) → the packets are framed.
  7. Physical (Cable) → the frames are converted into electrical signals.

The server receives in the reverse order: Physical → Data Link → Network … up to Application.

For Programmers​

  • The Application layer corresponds to your HTTP/HTTPS calls.
  • The Transport layer (TCP/UDP) explains issues of latency, timeout, packet loss.
  • The Network layer helps you understand IP addressing, client/server connection.
  • The Data Link and Physical layers are useful to know for diagnosing local network issues.

References​