All comparisonsNetworking

TCP vs UDP

TCP and UDP are both transport-layer protocols that sit on top of IP, but they trade off reliability against speed. TCP establishes a connection with a three-way handshake, numbers every segment, retransmits lost packets, and delivers data to the application in order. UDP just fires datagrams at the destination with no handshake, no retransmission and no ordering guarantee, so it has far less overhead per packet.

Left

TCP

Right

UDP

ConnectionConnection-oriented (handshake)Connectionless
OrderingGuaranteed in-order deliveryNo ordering guarantee
ReliabilityRetransmits lost segmentsPackets can be dropped silently
OverheadHigher (headers, ACKs, flow control)Minimal header, no ACKs
Typical useHTTP/HTTPS, SSH, database connectionsDNS, video/voice streaming, gaming

Use TCP when

You need every byte to arrive, in order, and can tolerate a bit of latency, e.g. loading a web page or replicating a database.

Use UDP when

Speed matters more than a dropped packet here and there, e.g. a live video call where a stale frame is worse than a missing one.

The verdict

TCP is the safe default for anything that must be correct. UDP earns its place when latency is the product, and the application layer (or the codec) can tolerate loss on its own.

Study this on the roadmap

Networking