TCP vs UDP
Both are Transport Layer (Layer 4) protocols. TCP is reliable and connection-oriented; UDP is fast and connectionless.
TCP
Transmission Control Protocol
ConnectionConnection-oriented (3-way handshake)
ReliabilityGuaranteed delivery
OrderData arrives in order
Error checkingYes — retransmits lost packets
Flow controlYes — sliding window
SpeedSlower (overhead)
Header size20–60 bytes
Use casesHTTP, FTP, SMTP, SSH
Pros
Reliable data delivery
Error detection & correction
Flow and congestion control
Ordered delivery
Cons
Higher overhead
Slower than UDP
Not suitable for real-time
UDP
User Datagram Protocol
ConnectionConnectionless
ReliabilityNo guarantee
OrderNo ordering
Error checkingBasic checksum only
Flow controlNone
SpeedFaster (low overhead)
Header size8 bytes (fixed)
Use casesDNS, VoIP, Video streaming, Gaming
Pros
Very fast
Low overhead
Good for real-time apps
Supports broadcast/multicast
Cons
No reliability
No ordering
No flow control
Packets may be lost
When to Use Which?
Use TCP when:
Data accuracy is critical (banking, file transfer)
Order of data matters
You need error recovery
HTTP/HTTPS web requests
Email (SMTP, IMAP)
Use UDP when:
Speed is more important than reliability
Real-time applications (VoIP, video calls)
Online gaming
DNS queries
Live streaming