๐Ÿ“ก Full Lesson ยท Networking
TCP: Reliable, Ordered, Slower | UDP: Fast, No Guarantees
TCP vs UDP

Two protocols at the Transport layer, built on opposite philosophies: one guarantees every byte arrives, in order, no matter what it costs in speed โ€” the other throws data at the destination and doesn't look back.

The Core Idea
Two Philosophies for Moving Data Across a Network

TCP (Transmission Control Protocol) is connection-oriented and reliable: before sending any actual data, it establishes a confirmed connection (the 'three-way handshake'), then guarantees every packet arrives, arrives in the correct order, and resends anything lost along the way. UDP (User Datagram Protocol) is connectionless and best-effort: it sends packets ('datagrams') immediately with no handshake, no ordering guarantee, and no automatic resending of lost packets.

Neither protocol is universally better โ€” TCP's guarantees come at the cost of overhead (the handshake, acknowledgments, and potential retransmission delays), while UDP's speed and simplicity come at the cost of zero built-in reliability. The right choice depends entirely on whether your specific application can tolerate occasional lost or out-of-order data in exchange for speed.

๐Ÿ’ก Memory Trick
TCP is a certified mail delivery service: before anything ships, sender and recipient confirm they're both ready (the handshake), every single package is tracked and numbered, and if one goes missing, it gets automatically resent โ€” slower, but nothing is ever silently lost. UDP is tossing postcards into a mailbox as fast as you can write them: no confirmation the recipient is even home, no tracking, and if one postcard gets lost in the mail, nobody resends it โ€” but you can write and send postcards far faster than arranging certified deliveries.
The Key Differences
Connection, Reliability, and Overhead
1
Connection Setup
TCP requires a 'three-way handshake' (SYN, SYN-ACK, ACK) before any actual application data is sent, establishing a confirmed connection between both endpoints. UDP has no handshake at all โ€” the sender simply starts transmitting datagrams immediately, with no confirmation the receiver is even listening.
2
Reliability and Ordering
TCP guarantees every byte sent arrives at the destination, in the exact order it was sent, using sequence numbers and acknowledgments โ€” if a packet is lost, TCP automatically detects this and retransmits it. UDP provides none of this: packets can arrive out of order, arrive duplicated, or simply never arrive at all, with no automatic detection or correction built into the protocol itself.
3
Overhead and Speed
TCP's reliability mechanisms (handshake, acknowledgments, retransmission, flow control) add real overhead and latency to every connection. UDP's simplicity โ€” no handshake, no acknowledgments, no retransmission โ€” makes it significantly faster and lower-latency, at the direct cost of any delivery guarantee.
Choosing Between Them
Matching Protocol to Application Tolerance for Loss

Choose TCP when correctness matters more than raw speed and any data loss would be unacceptable โ€” web browsing (HTTP/HTTPS), file transfers, and email all rely on TCP, since a corrupted webpage or a file missing random bytes would be a serious problem, and the added latency of guaranteed delivery is an acceptable trade-off.

Choose UDP when speed and low latency matter more than perfect reliability, and the application can gracefully tolerate some data loss โ€” live video/audio streaming, online gaming, and DNS lookups typically use UDP, because a single dropped video frame or a slightly-stale game-state update is far less disruptive than the delay TCP's retransmission-and-reordering guarantees would introduce; by the time a lost frame could be resent and reordered, the live moment has already passed anyway.

๐Ÿ–ฅ๏ธ Applied Scenario
You're building both a file-download feature and a live video call feature for the same application, and need to choose the transport protocol for each.
1
For the file download, you choose TCP: every single byte of the file must arrive correctly and in order, or the downloaded file will be corrupted โ€” the added latency from TCP's reliability guarantees is a completely acceptable trade-off here.
2
For the live video call, you choose UDP instead: if TCP were used and a packet were lost, TCP would pause the entire stream waiting to retransmit and correctly reorder that lost packet โ€” by the time it arrived, the live conversation would already be several seconds ahead, making the delayed frame useless anyway.
3
With UDP for video, a single lost frame just causes a brief visual glitch that's barely noticeable and is immediately superseded by the next frame โ€” far preferable to TCP's guaranteed-but-delayed delivery for this real-time use case.
4
Conclusion: the same application correctly uses both protocols simultaneously, because the file transfer and the live video call have fundamentally different tolerances for loss versus latency.
๐Ÿ“Œ Exam Application
Exam questions frequently ask you to identify which protocol (TCP or UDP) a described application should use, expecting you to justify the answer based on that application's specific tolerance for data loss versus its sensitivity to latency. You may also be asked to describe TCP's three-way handshake process or to explain, conceptually, why UDP has lower latency and overhead than TCP.
โš ๏ธ Most Common TCP vs UDP Mistakes
The most common mistake is assuming TCP is simply 'better' because it's reliable โ€” for real-time applications like live video or gaming, TCP's guaranteed-delivery mechanism can actually make the experience WORSE, since waiting for a retransmitted, correctly-ordered packet introduces a delay that's often more disruptive than just dropping and moving past the lost data, which is exactly what UDP allows. Another frequent error is assuming UDP provides zero reliability at the application level โ€” some applications built on top of UDP add their own custom reliability or ordering logic in the application layer itself (as some video game networking and streaming protocols do), rather than relying on TCP's built-in guarantees.
โœ“ Quick Self-Test
Can you explain, in one sentence, the fundamental trade-off between TCP and UDP? Given a described application (file transfer, live gaming, DNS lookup, video streaming), can you correctly identify and justify which transport protocol it should use?
Next Lesson
DNS
โ†’
โ† All Networking Lessons