Network security

TCP vs UDP: What's the Difference and When to Use Each?

TCP guarantees delivery in order; UDP sends fast and does not look back. Here is how the handshake, headers, and ports differ — and which one your apps use.

Cysoro Security TeamPublished · 7 min read
TCPReliable · Ordered20-byte headerUDPFast · Best effort8-byte headervsSYN → SYN-ACK → ACK NETWORK SECURITY TCP vs UDP Reliability or speed? How to choose.
Quick answer

TCP is a connection-oriented, reliable transport protocol that uses a three-way handshake, sequence numbers, and retransmission to deliver data in order, with a header of at least 20 bytes. UDP is connectionless and unreliable by design: it sends independent datagrams with an 8-byte header, no handshake, and no retransmission, trading reliability for speed and low overhead.

Key takeaways

  • TCP is reliable, ordered, and connection-oriented; UDP is fast, connectionless, and best-effort.
  • TCP uses a three-way handshake (SYN, SYN-ACK, ACK) and a 20-byte header; UDP has no handshake and an 8-byte header.
  • Use TCP for web, email, and file transfer; use UDP for DNS, gaming, voice, and live video where speed matters more.

Almost every packet on the internet travels over TCP or UDP. They sit at the same layer, carry the same kind of payload, and both use ports — yet they make opposite trade-offs. TCP spends time and header space to guarantee delivery. UDP skips all of that and fires datagrams with almost no overhead.

What is TCP?

TCP, the Transmission Control Protocol, is a connection-oriented transport protocol that delivers a reliable, ordered byte stream between two hosts. It is defined in RFC 793 and is the protocol behind most web browsing, email, and file transfer.

TCP establishes a connection before any application data moves, using a three-way handshake. It then numbers every byte, acknowledges receipt, retransmits lost segments, reorders data that arrives out of sequence, and controls flow so a fast sender does not overrun a slow receiver.

That reliability costs time and overhead: the handshake takes a full round trip before data flows, and every TCP header is at least 20 bytes. For applications where every byte must arrive in order — a web page, an email, a file — that cost is worth paying.

What is UDP?

UDP, the User Datagram Protocol, is a connectionless transport protocol that sends independent datagrams with minimal overhead. It is defined in RFC 768 and is the protocol behind DNS, DHCP, NTP, online gaming, voice calls, and live video.

UDP has no handshake, no connection state, no acknowledgments, and no retransmission. The sender puts data in a datagram and sends it; the receiver may get it, may get it out of order, or may not get it at all. UDP itself does nothing to correct that.

UDP does include a checksum to detect corruption in datagrams that do arrive, and it preserves datagram boundaries: one datagram sent by the application is delivered as one datagram if it arrives. Its header is only 8 bytes, compared with TCP's minimum of 20 bytes, which is why it is faster for small, time-sensitive messages.

What is the difference between TCP and UDP?

The core difference is reliability versus speed. TCP guarantees ordered, complete delivery and pays for it with a handshake, acknowledgments, and a larger header. UDP guarantees nothing and pays almost nothing, leaving reliability to the application if it needs it.

PropertyTCPUDP
ConnectionConnection-oriented; handshake firstConnectionless; no setup
ReliabilityAcknowledged and retransmittedNone — best effort only
OrderingDelivered in order by sequence numberDatagrams may arrive out of order
Data modelContinuous byte streamIndependent datagrams
Flow controlWindowing built inNone — application must handle it
Congestion controlBuilt inNone
Header size20 bytes minimum8 bytes fixed
SpeedSlower due to handshake and checksFaster due to minimal overhead
Typical usesHTTP, HTTPS, SSH, FTP, SMTP, IMAPDNS, DHCP, NTP, VoIP, gaming, streaming

Both protocols sit at Layer 4, the transport layer, above IP at Layer 3. They receive data from higher-level applications, encapsulate it, and forward it to the IP layer, as described in the Akamai guide to TCP and UDP.

TCP vs UDP at a glanceTCPHandshake: SYN, SYN-ACK, ACKHeader: 20+ bytesReliable, ordered, retransmittedWeb, email, file transferUDPHandshake: noneHeader: 8 bytesBest effort, no retransmissionDNS, gaming, voice, live video
TCP trades speed for reliability; UDP trades reliability for speed. Illustration by Cysoro.

How does the TCP three-way handshake work?

The three-way handshake is how TCP establishes a connection: the client sends SYN, the server replies SYN-ACK, and the client answers ACK. Only after that exchange does application data flow, which costs one round trip before anything useful moves.

Each side also picks an initial sequence number during the handshake. Those numbers let TCP track which bytes have been sent, which have been acknowledged, and which are missing. If a segment goes missing, the receiver keeps acknowledging the last in-order byte it has, and the sender retransmits when its timer expires.

Closing a connection is a separate four-step exchange, with FIN and ACK messages in each direction. UDP has no equivalent: there is no connection to open or close, so the first datagram is also the first data.

The TCP three-way handshakeClientServer1. SYN2. SYN-ACK3. ACKConnection established — application data can now flow.
SYN, SYN-ACK, ACK — one round trip before any application data moves. Illustration by Cysoro.

How do TCP and UDP ports work?

Both TCP and UDP use 16-bit port numbers to direct traffic to the right application on a host. A communication port is associated with each application using the transport layer, and the TCP and UDP headers each include source and destination port fields.

Crucially, TCP and UDP maintain completely independent port numbering systems. TCP port 2000 and UDP port 2000 are different and can both be used at the same time. Popular applications are assigned official well-known ports: 80 for HTTP, 443 for HTTPS, 25 for SMTP, 22 for SSH, and 53 for DNS (which uses both TCP and UDP).

On Linux you can see which protocol a port uses with tools such as ss -tuln, which lists listening TCP and UDP sockets separately. On a firewall, always specify the protocol as well as the port — opening TCP 53 is not the same as opening UDP 53.

When should you use TCP?

Use TCP when every byte must arrive, in order, and completeness matters more than speed. Web browsing, email, file transfer, remote login, and database connections all use TCP because a missing or reordered byte would corrupt the result.

HTTPS, the protocol behind almost all web traffic, runs over TCP (for HTTP/1.1 and HTTP/2). Email protocols — SMTP, IMAP, and POP3 — also use TCP, as do SSH and FTP. If your application cannot tolerate loss or reordering, TCP is the default choice.

TCP also helps on unreliable networks. Its retransmission, flow control, and congestion control adapt to packet loss and varying bandwidth, which is why file downloads complete correctly even on a flaky connection. For home networks, our guide to how to secure your Wi-Fi covers the settings that keep that connection reliable.

When should you use UDP?

Use UDP when speed and low latency matter more than guaranteed delivery, and when the application can handle loss itself. DNS, DHCP, NTP, online gaming, voice calls, and live video all use UDP for this reason.

DNS is the classic example: a query is a small, single request-and-response exchange, and if it is lost the client simply retries. A handshake and retransmission for every lookup would slow down every web page load. Similarly, a late game update or video frame is worse than a lost one — retransmitting it would arrive too late to matter.

Modern protocols also build reliability on top of UDP when they need it. HTTP/3 runs over QUIC, which is built on UDP but adds its own reliability, ordering, and encryption above it. That combination gives you TCP-like guarantees without TCP's head-of-line blocking.

Is TCP or UDP more secure?

Neither TCP nor UDP is secure on its own. Neither encrypts packets, and both are vulnerable to spoofing and denial-of-service attacks. TCP is susceptible to SYN floods and connection hijacking, while UDP's lack of a handshake makes it useful for amplification attacks, where a small spoofed request triggers a large response to a victim.

Security comes from the layers above transport: TLS encrypts web traffic, VPNs encrypt the whole connection, and authentication proves who you are talking to. Firewalls often limit UDP more strictly than TCP because UDP has no connection state to track, which is why some UDP-based services need explicit firewall rules.

For practical network security, check that your public services use TLS and current headers. Our free security headers checker shows whether a site's transport security is configured correctly.

Run the SSL checker on any public site to confirm its certificate and TLS settings are valid.

Opening a port is not enoughAlways specify TCP or UDP when you open a firewall port. Opening the wrong protocol leaves the service unreachable, and opening both when only one is needed widens your attack surface for no benefit.

What mistakes do people make with TCP and UDP?

The most common mistakes are assuming UDP is always faster, assuming TCP is always more secure, and forgetting that the two port systems are independent. Each of these leads to real configuration errors.

  • Assuming UDP is always faster. Its smaller header and lack of handshake reduce latency, but real performance depends on the application, network conditions, and any reliability mechanisms added above UDP.
  • Assuming TCP is secure. TCP does not encrypt anything. Without TLS, TCP traffic is readable by anyone on the path.
  • Confusing TCP and UDP ports. A service listening on UDP 53 will not answer a TCP 53 query, and vice versa.
  • Blocking UDP entirely. That breaks DNS, NTP, and many voice and gaming services. Filter UDP thoughtfully instead.

If you are learning networking, the Linuxize guide to TCP vs UDP includes practical commands for checking which protocol a port uses on a Linux system.

The bottom line

TCP and UDP are not rivals — they are tools for different jobs. TCP is the right choice when data must arrive complete and in order. UDP is the right choice when speed matters and the application can live with occasional loss.

When you choose, ask one question: what happens if a packet is lost? If the answer is corruption or failure, use TCP. If the answer is a skipped frame or a quick retry, use UDP. You can check how your own connection handles DNS — a UDP service — with the free DNS lookup tool.

Frequently asked questions

What is the main difference between TCP and UDP?

TCP is connection-oriented and reliable: it establishes a connection, tracks sequence numbers, acknowledges receipt, and retransmits lost data in order. UDP is connectionless and best-effort: it sends datagrams without a handshake, acknowledgment, or retransmission.

Is TCP or UDP faster?

UDP is faster in most cases because it has no handshake, no acknowledgments, and a smaller 8-byte header, compared with TCP's minimum 20-byte header. TCP is not always slower in practice, though, because modern TCP and the application protocol above it also affect speed.

Does TCP or UDP use ports?

Both use ports. Each has a 16-bit source and destination port field, and TCP and UDP port numbers are independent: TCP port 2000 and UDP port 2000 are different and can both be used at the same time. Well-known ports include 80 and 443 for web traffic and 53 for DNS.

Why does DNS use UDP?

DNS usually uses UDP because queries are small, single request-and-response exchanges where speed matters more than guaranteed delivery. If a query is lost, the client simply retries, and if a response is too large, DNS can fall back to TCP.

Why do games and video calls use UDP?

Games, voice calls, and live video use UDP because a late packet is worse than a lost one. A retransmitted game update arrives too late to matter, while a dropped video frame is barely noticeable. The application handles any loss itself.

Is UDP less secure than TCP?

UDP is not encrypted either, and both protocols are vulnerable to spoofing and denial-of-service attacks. UDP's lack of a handshake makes UDP-based amplification attacks possible, which is why firewalls often limit UDP. Security comes from TLS, VPNs, and authentication above the transport layer, not from TCP or UDP themselves.

What is the TCP three-way handshake?

The three-way handshake is SYN, SYN-ACK, ACK. The client sends SYN, the server replies SYN-ACK, and the client answers ACK. Only after that exchange does application data flow. The handshake costs one round trip before any data moves.

Can an application use both TCP and UDP?

Yes. Many applications use both: DNS uses UDP for most queries and TCP for large responses and zone transfers, and some video services use UDP for media and TCP for control. HTTP/3 runs over QUIC, which is built on UDP but adds reliability above it.

Sources

  1. Akamai / Linode — The Difference Between TCP and UDP Explained
  2. Linuxize — TCP vs UDP: Differences and When to Use Each
  3. ComputingForGeeks — TCP vs UDP Explained: Handshake and Ports
  4. IETF — RFC 793: Transmission Control Protocol
  5. IETF — RFC 768: User Datagram Protocol
  6. Cloudflare — What is TCP?
Written & fact-checked byCysoro Security Team

The engineers and analysts who build Cysoro's domain scanner, email-authentication checks and free security tools. We test what we write about every day — SPF, DKIM, DMARC, certificates, look-alike domains and phishing — and check each guide against the relevant standards, government guidance and vendor documentation.

  • Email authentication
  • Phishing & BEC
  • Domain & DNS security
  • Small-business security

Checked against RFC 793 (TCP), RFC 768 (UDP), and Akamai, Linuxize, and ComputingForGeeks protocol guides.

How we write and fact-check →

Free tools for this topic

No account needed.

See where your domain stands

Free for up to 3 domains. No card, no installs.

Start free