Both are transport-layer protocols that carry data between applications using port numbers. TCP trades speed for reliability; UDP trades reliability for speed.
TCP UDP
Connection Yes, three-way handshake first No, just send
Reliability Lost packets are re-sent No re-sending
Ordering Delivered in order May arrive out of order
Flow/congestion Yes, slows down when needed No
Header size 20 bytes minimum 8 bytes
Data unit Byte stream Individual datagrams
Speed Slower, more overhead Faster, less overhead
How TCP is reliable
It numbers every byte (sequence numbers), the receiver acknowledges what it got (ACKs), and anything not acknowledged in time is re-sent. A window controls how much can be in flight, and congestion control slows the sender when the network is busy. The connection starts with SYN, SYN-ACK, ACK and ends with FIN messages.
Uses
- TCP: web pages (HTTP/1.1 and HTTP/2), email (SMTP, IMAP), file transfer (FTP, SFTP), SSH, database connections. Anything where every byte must arrive correctly.
- UDP: DNS lookups, video calls and voice over IP, live streaming, online games, DHCP. Here a late packet is useless, so re-sending it would only add delay.
A good extra point
HTTP/3 runs on QUIC, which is built on UDP. QUIC adds its own reliability and encryption in user space, avoiding TCP’s head-of-line blocking and making connections faster to set up. So “UDP is unreliable” is about the protocol itself, not what applications build on it.
Follow-ups
- Explain the TCP three-way handshake.
- Which layer of the OSI model do TCP and UDP belong to?
- What is a port, and name some well-known ones (80, 443, 22, 53)?
This answer was written by Debugger’s Space as practice material. See how HCLTech hires, step by step, and more HCLTech practice questions.