Imagine sending 100 letters to a friend. TCP ensures every letter arrives, in order, and resends any that get lost. UDP throws them all into a leaf blower aimed at your friend’s house. Some make it, some don’t, but it’s really fast.
Introduction
TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are the two languages of the Transport Layer. Every piece of data sent over the internet — from this website to your Netflix stream — uses one of them.
- How TCP creates a connection (The 3-Way Handshake)
- Why UDP is faster but “unreliable”
- When to use which (Email vs Gaming)
- Practical commands to see them in action
TCP: The Reliable Perfectionist
TCP cares about one thing: Reliability. When you load a webpage or send an email, you can’t afford to lose a single byte. A missing letter in an email changes the meaning. A missing bracket in code breaks the app.
How TCP works:
- Connects: Establishes a formal connection (Handshake).
- Numbers: Numbers every packet (1, 2, 3…).
- Acknowledges: Receiver says “Got packet 1, send 2”.
- Resends: If packet 2 goes missing, TCP sends it again.
- Reorders: If packet 3 arrives before 2, TCP fixes the order.
UDP: The Speed Demon
UDP cares about one thing: Speed. It doesn’t care if packets are lost. It doesn’t care about order. It just blasts data.
Used for: Live streaming, VoIP calls, Online Gaming. Why? If you miss a frame in a video call, you don’t want the video to pause and wait for it. You just want the next frame immediately. “Real-time” matters more than “Perfect”.
Comparison Table
| Feature | TCP (Reliable) | UDP (Fast) |
|---|---|---|
| Connection | Connection-oriented (Handshake) | Connection-less (Fire & Forget) |
| Reliability | Guaranteed delivery | No guarantee |
| Ordering | Guaranteed 1-2-3 | Arrival order random |
| Speed | Slower (overhead) | Blazing fast |
| Use Cases | Web (HTTP), Email (SMTP), SSH, FTP | DNS, Streaming, VoIP, Gaming |
Hands-On: Seeing Connections
You can see which connections your computer has open right now.
Linux / Mac:
Show listening TCP (t) and UDP (u) ports
Windows:
Show active TCP connections
Protocol Examples
When you type google.com, you want the IP specific immediately. If the request fails, your computer just asks again. A handshake would make browsing verify slow.
Actually, Netflix uses TCP (over HTTP) because they buffer the video. If a packet is lost, there’s time to resend it before you see the glitch. However, Zoom calls use UDP because they are live — you can’t buffer a live conversation.
Quiz: Test Your Knowledge
Test Your Knowledge
Take a quick 4-question quiz to check your understanding.