Back/TCP/IP & The OSI Model
Lesson 24 min

TCP/IP & The OSI Model

00:00 / 00:00

What is TCP/IP?

TCP/IP (Transmission Control Protocol / Internet Protocol) is the foundational communication language of the internet. It is a suite of protocols — a set of rules — that governs how data is transmitted, addressed, routed, and received between devices.

TCP/IP is not one protocol. It is a stack of four cooperative layers, each with a distinct responsibility.

The Four Layers of TCP/IP

  • Application Layer — The layer your applications live in. HTTP, HTTPS, FTP, DNS, SMTP all operate here.
  • Transport Layer — Responsible for end-to-end communication. TCP provides reliable, ordered delivery. UDP provides fast, connectionless delivery.
  • Internet Layer — Handles logical addressing and routing. The IP protocol lives here, assigning IP addresses and routing packets across networks.
  • Network Access Layer — The physical layer. Ethernet, Wi-Fi — how bits are physically transmitted over cables and radio waves.

The OSI Model: 7 Layers Deep

The OSI (Open Systems Interconnection) model is a conceptual framework used to understand network communication. Unlike TCP/IP's 4 layers, OSI has 7:

  • Layer 7 — Application → HTTP, FTP, DNS
  • Layer 6 — Presentation → Encryption (TLS/SSL), Data formatting
  • Layer 5 — Session → Manages connections (login sessions)
  • Layer 4 — Transport → TCP / UDP
  • Layer 3 — Network → IP, Routing
  • Layer 2 — Data Link → MAC addresses, Ethernet frames
  • Layer 1 — Physical → Cables, radio waves, fiber optics

TCP vs UDP: When to Use What

python
# TCP is like a phone call — you establish a connection first # UDP is like sending a letter — fire and forget # Use TCP for: HTTP, file transfers, emails (reliability matters) # Use UDP for: video streaming, gaming, DNS (speed matters) import socket # TCP Socket Example tcp_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # STREAM = TCP tcp_socket.connect(('google.com', 80)) # UDP Socket Example udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # DGRAM = UDP udp_socket.sendto(b'Hello', ('8.8.8.8', 53))

The Three-Way Handshake

Before any TCP data transfer, a connection must be established using the three-way handshake:

  • SYN — Client sends a synchronize request to the server.
  • SYN-ACK — Server acknowledges the request and sends its own.
  • ACK — Client acknowledges, and the connection is established.

This is why TCP is reliable but slightly slower than UDP — it verifies the connection before sending data.

Summary

TCP/IP is the language computers use to talk to each other. The OSI model helps us reason about where in that communication chain something is happening. As a backend developer, you will primarily work at the Application Layer — but understanding the layers below is what separates a good engineer from a great one.

WhatsApp