</>
ShikshaCSLearn. Code. Grow.
๐Ÿ”
โ˜• Support Us
ShikshaCSโ€บNotesโ€บComputer Networks
Computer Networks
๐Ÿ•’ 9 min read

TCP vs UDP

The two ways data actually travels across the Transport layer โ€” reliable vs fast.

What the Transport Layer Does

The Transport layer is responsible for end-to-end communication between two devices, taking data from the Application layer above and preparing it for delivery across the network below. Its two main protocols, TCP and UDP, represent two fundamentally different philosophies for how that delivery should work.

TCP โ€” Reliable but Slower

TCP (Transmission Control Protocol) is connection-oriented โ€” it establishes a connection first (via the 3-way handshake), then guarantees that data arrives completely, in the correct order, and re-transmits anything lost. This reliability comes at a cost: extra overhead (acknowledgments, sequence tracking) makes TCP slower than UDP for the same amount of raw data.

UDP โ€” Fast but No Guarantees

UDP (User Datagram Protocol) is connectionless โ€” it simply sends data (called datagrams) without establishing a connection first, and without any guarantee of delivery, order, or error recovery. If a packet is lost, UDP doesn't notice or resend it. This makes UDP significantly faster and lower-overhead than TCP, at the cost of reliability.

When to Use Which

Use TCP when correctness matters more than speed โ€” web browsing (a webpage must load completely and correctly), file downloads, email, and any file transfer. Use UDP when speed and low latency matter more than perfect accuracy โ€” live video calls, online gaming, and live streaming, where a few dropped frames/packets are far less noticeable than laggy delays waiting for retransmission.

A Simple Analogy

TCP is like sending a registered letter โ€” you get confirmation it arrived, and if it's lost, the postal service resends it, but this takes more time and paperwork. UDP is like shouting a message across a room โ€” fast and immediate, but if someone doesn't hear it, there's no automatic system to check or repeat it.

๐ŸŒ Real-World Use

When you browse a website, TCP ensures every piece of that page (text, images, scripts) arrives completely and correctly. When you're on a video call and it briefly glitches or a frame freezes for a split second, that's UDP prioritizing speed over perfect delivery โ€” waiting to fix that one lost frame would make the whole call feel more laggy, not less.

๐Ÿ’ก Pro Tip

A near-guaranteed interview question: 'why does DNS use UDP but a file download uses TCP?' โ€” the answer is that a DNS lookup is a single tiny quick request/response where speed matters most (and can simply be retried if it fails), while a file download needs every single byte correctly and in order, which only TCP guarantees.

๐Ÿงช Quick Self-Test

Check what you just learned โ€” no pressure, just practice.

1. Which protocol establishes a connection before sending data?

2. Why is UDP preferred for live video calls over TCP?

3. What happens if a UDP packet is lost in transit?

โ† Back to all Notes