18 min read Intermediate Lesson 26 of 30
Part 5 — Transport Layer & Network Protocols

IP, TCP & UDP: How Data Reaches the Right Application

IP addresses deliver packets to the correct host machine. But among the browser, Discord, video game, and Spotify running concurrently on that computer, how does each packet reach the right application? How does TCP recover lost packets, and why does competitive gaming rely on UDP?

Registered Mail vs Flying Postcards

TCP is certified postal mail—the sender will not rest until the recipient signs and returns an acknowledgment (ACK); if a letter goes missing, it is retransmitted.

UDP is a postcard tossed from a moving train—it arrives instantly, but if one blows away in the wind, nobody stops the train to look for it.

1–4. IP Limitations & the Need for Transport Ports

The IP layer provides only "Best-Effort" packet delivery—it provides no guarantees against packet loss, reordering, or duplication. That responsibility falls on the Transport Layer:

Port Numbers (16-bit)

Ports range from 0 to 65,535.
Well-Known (0–1023): 80 (HTTP), 443 (HTTPS), 53 (DNS), 22 (SSH).
Ephemeral (49152–65535): Dynamically assigned to client applications by the OS.

Socket Pair (Unique Connection)

Every internet connection is uniquely identified across the globe by a 4-tuple:
(Source IP : Port) <──► (Dest IP : Port)

5–15. TCP: The Reliable 3-Way Handshake & Sequencing

Before transmitting application data, TCP establishes a verified bidirectional virtual circuit:

─── TCP 3-Way Handshake ───
Client ───────────────── [ SYN (Seq=100) ] ─────────────────► Server
Client ◄────────── [ SYN-ACK (Seq=300, Ack=101) ] ────────── Server
Client ───────────────── [ ACK (Seq=101, Ack=301) ] ─────────────────► Server
✔ Connection Established — Reliable Data Transfer Begins!

Sequence & ACK Numbers

Every byte transmitted has a sequence number. Even if packets arrive out of order across divergent routes, the receiver reconstructs the byte stream correctly.

Retransmission on Loss

If an ACK is not received before a retransmission timer expires, TCP assumes the packet was dropped by a congested router and automatically retransmits.

16–21. Flow Control vs Congestion Control

Flow Control (Sliding Window)

The receiver announces its free RAM buffer size (rwnd) in each ACK packet, preventing a fast sender from flooding a slow recipient.

Congestion Control (AIMD)

To prevent router buffer overruns across the internet, TCP ramps up transmission speeds cautiously (Slow Start) and halves its transmission rate upon detecting packet loss.

22–26. UDP: Ultra-Fast Real-Time Communication

Where millisecond speed and low latency take precedence over absolute 100% perfection, networks rely on UDP:

  • Compact 8-Byte Header: Dramatically lighter than TCP's 20–60 byte header.
  • Zero Handshake Latency: Payload data is transmitted immediately in the very first packet.
  • Typical Use Cases: Real-time gaming (Valorant/CS2), voice/video calls (Zoom/WebRTC), live streaming, and DNS lookups.

27–31. TCP vs UDP Comprehensive Comparison Table

Feature TCP (Transmission Control Protocol) UDP (User Datagram Protocol)
Connection Type Connection-Oriented (3-way handshake) Connectionless (no handshake)
Reliability 100% Guaranteed (Automatic Retransmission) Best-effort (packets may drop)
Ordering Strictly sequenced and reassembled No ordering guarantee
Speed & Overhead Moderate speed, 20–60 byte header Ultra-fast, minimal 8-byte header
Primary Uses Web (HTTP/HTTPS), Email, File Downloads Gaming, Voice, Video Streaming, DNS

36–40. Master Transport Layer Communication Model

[ CLIENT: Chrome Browser ] ──► (Source: 192.168.1.10 : Ephemeral Port 54321) │ │ 1. TCP 3-Way Handshake (SYN ──► SYN-ACK ──► ACK) ▼ [ OS TCP STACK & SLIDING WINDOW ] ──► Packet Flow & Congestion Control │ │ 2. Segment Encapsulated into IP Packet ▼ [ GLOBAL INTERNET ROUTERS ] ──► Routed across Fiber Links │ │ 3. Delivers to Web Server IP ▼ [ SERVER OS TCP STACK ] ──► Reads Port 443 ──► Directs to NGINX Process!

🧠 Key Takeaways

  • IP vs Transport: IP locates the host computer; the transport layer delivers data to the specific application port.
  • Ports & Sockets: 16-bit port numbers and socket pairs uniquely distinguish inter-process network channels.
  • TCP Handshake: SYN and ACK synchronize initial sequence numbers, guaranteeing reliable, ordered byte delivery.
  • Flow & Congestion Control: Sliding windows and AIMD algorithms prevent receiver buffer overflows and global internet congestion collapse.
  • UDP: A lightweight, connectionless protocol that powers latency-critical gaming, live streaming, and voice services.
🚀 Next Lesson

Lesson 27 — DNS: How Domain Names Turn into Server IP Addresses

Learn how the distributed Domain Name System hierarchy resolves human-friendly names to IP addresses across root, TLD, and authoritative nameservers.