UDP vs TCP: Core Differences Explained
TCP is a connection-oriented, reliable protocol with error recovery, while UDP is a connectionless, fast, best-effort protocol without guaranteed delivery.
TCP: Transmission Control Protocol
**TCP** is a connection-oriented protocol operating at Layer 4. It ensures reliable delivery using a 3-way handshake (SYN, SYN-ACK, ACK) before data transmission. TCP features error recovery, sequencing, and flow control (windowing), making it ideal for HTTP, SSH, and file transfers.
UDP: User Datagram Protocol
**UDP** is a connectionless protocol. It simply sends data without checking if the destination is ready or if the data was received. Because it lacks overhead like handshakes and sequencing, it is much faster than TCP. UDP is used for real-time applications like VoIP, streaming video, and DNS.
Comparing the Headers
The **TCP header** is complex, typically 20 bytes long, containing fields for sequence numbers, acknowledgment numbers, and flags. The **UDP header** is incredibly lightweight, at just 8 bytes, containing only source port, destination port, length, and a checksum.
❓ Frequently Asked Questions
Why is UDP used for voice and video?
Voice and video require real-time transmission where speed is more important than perfect reliability. Retransmitting dropped packets would cause noticeable lag.
What is the TCP 3-way handshake?
It is the process used to establish a TCP connection: SYN, SYN-ACK, and ACK.
Does DNS use TCP or UDP?
DNS uses UDP for standard queries and TCP for zone transfers.