Difference Between TCP and UDP

TCP and UDP are the two transport layer protocols that carry nearly all internet traffic, making choosing between them a critical decision in network design for cybersecurity and ethical hacking. Every web page load, video stream, DNS query, and VoIP call travels via either TCP or UDP, both operating at Layer 4 of the OSI model. The difference between these protocols determines reliability, speed, overhead, and attack surface.

TCP (Transmission Control Protocol)

Connection-oriented

TCP, or Transmission Control Protocol, is a connection-oriented transport layer protocol that guarantees reliable data delivery across networks. It establishes a three-way handshake, ensures packets arrive in the correct order, and retransmits lost packets. TCP powers web browsing, email, and file transfers. While slower than UDP, TCP provides error checking and congestion control. Every ethical hacker must understand TCP because its predictable handshake can be exploited for denial of service attacks such as SYN floods.

  • Establishes a connection before data transfer via a three-way handshake
  • Guarantees that the delivery of lost packets is detected and retransmitted
  • Delivers data in the correct order, even if packets arrive out of sequence
  • Higher overhead headers, acknowledgements, and flow control add latency
  • Used where accuracy matters: HTTP, HTTPS, SSH, FTP, email.

UDP (User Datagram Protocol)

Connectionless

UDP (User Datagram Protocol) is a connectionless transport-layer protocol that sends data without establishing a handshake or verifying delivery. It offers no guarantees, no packet ordering, and no retransmission of lost data. UDP powers video streaming, VoIP calls, online gaming, and DNS queries. Much faster than TCP but completely unreliable. Ethical hackers must understand UDP because its lack of verification creates vulnerabilities for amplification attacks such as DNS reflection and UDP floods.

  • No handshake sends data immediately without establishing a connection
  • No delivery guarantee; packets can be lost with no notification
  • No ordering datagrams may arrive out of sequence
  • Minimal overhead, small header, no acknowledgement round-trips
  • Used where speed matters: DNS, VoIP, video streaming, gaming, and DHCP.

The TCP three-way handshake

Before TCP transmits a single byte of data, it establishes a reliable connection through a three-step process called the three-way handshake. This is what makes TCP connection-oriented, and it is also what makes it vulnerable to SYN flood attacks.

The TCP SYN flood attack exploits the three-way handshake by sending massive volumes of SYN packets without completing the handshake leaving the server with thousands of half-open connections that exhaust its connection table. This is one of the most common DDoS techniques, defended against using SYN cookies and rate limiting at the firewall.

Side-by-side comparison

AttributeTCPUDP
Connection typeConnection-orientedConnectionless
Handshake3-way (SYN/SYN-ACK/ACK)None
ReliabilityGuaranteed deliveryBest-effort — no guarantee
OrderingIn-order deliveryNo ordering
SpeedIn-order deliveryFaster — minimal overhead
Header size20–60 bytes8 bytes
Flow controlYes — sliding windowNo
Error checkingYes — checksum + retransmitChecksum only (optional) 

UDP’s lack of a handshake makes it ideal for UDP-based DDoS amplification attacks. Attackers spoof the victim’s IP as the source and send small UDP requests to misconfigured DNS or NTP servers, which respond with much larger replies to the victim — amplifying the attack traffic by a factor of up to 4,000× in some NTP reflection attacks.

Real-world use cases — which protocol uses which

TCP Use Case
 
Web browsing (HTTPS)
 
 
Every byte of a web page must arrive correctly and in order. A missing packet means broken HTML, CSS, or JavaScript, TCP’s re-transmission ensures completeness.
 
 TCP 443
UDP Use Case
 
DNS queries
 
 
DNS requests are tiny and latency-sensitive. A dropped query simply retries — UDP’s speed makes it ideal, and most DNS responses fit in a single datagram.
 UDP 53 
TCP Use CaseSSH & remote access
 
 
Every keystroke and command must arrive intact and in sequence. Lost packets in an SSH session would produce corrupted commands, TCP guarantees correct delivery.
 TCP 22 
UDP Use CaseVideo streaming & VoIP
 
 
A dropped video frame or voice packet is imperceptible — but the delay caused by TCP retransmission would cause stuttering. UDP drops frames gracefully.
 UDP 5004
TCP Use CaseEmail (SMTP)
 
 
Email must be delivered completely and correctly — a partial email is worse than no email. TCP’s reliability guarantee makes it the only choice for mail transfer.
 TCP 25 / 587
TCP Use Case
 Web browsing (HTTPS)
 
 
Every byte of a web page must arrive correctly and in order. A missing packet means broken HTML, CSS, or JavaScript; TCP’s re-transmission ensures completeness.
 
 TCP 443

In penetration testing, Nmap uses TCP SYN scans by default (-sS) — sending SYN packets and checking for SYN-ACK responses without completing the handshake. For UDP port discovery, nmap -sU is used — but UDP scans are significantly slower because closed ports respond with ICMP unreachable messages while open ports often produce no response at all.

Scroll to Top