TCP vs UDP: Differences, Ports and When Each Is Used

TCP and UDP are the two main transport protocols on the internet. TCP sets up a connection first and guarantees that data arrives complete and in order; UDP just fires off independent packets with no delivery guarantees at all, which is exactly what makes it simpler and faster for real-time traffic like games, voice calls and DNS.

Both sit on top of IP, both use port numbers to identify applications — but from there, they make opposite trade-offs. Knowing which one a given service actually uses matters a lot when you're opening a firewall, setting up port forwarding, or troubleshooting a connection that only half works.

TCP vs UDP at a glance

TCPUDP
SpecificationRFC 9293 (replacing the original RFC 793)RFC 768
ConnectionConnection-oriented, three-way handshakeConnectionless, no handshake
ReliabilityAcknowledgements and retransmissionNone; lost packets stay lost
OrderingDelivered in order as a byte streamEach datagram independent; may arrive out of order
Flow and congestion controlYes, built inNo; the application must handle it
Header size20 bytes minimum, up to 60 with options8 bytes
Broadcast and multicastNot supportedSupported
Typical usesWeb, email, SSH, file transfer, databasesDNS, DHCP, VoIP, video calls, games, QUIC

How TCP works

The three-way handshake

Before a single byte of data flows, the two sides have to agree to talk first:

  1. The client sends a SYN segment with a random initial sequence number.
  2. The server answers with SYN-ACK, acknowledging the client's number and choosing its own.
  3. The client sends ACK. The connection is now established.

That whole exchange costs one round trip before any actual data moves. On a link with 80 ms latency, a fresh TCP connection waits at least 80 ms just for that — plus whatever a TLS handshake adds on top, if the connection is encrypted.

Reliability and ordering

TCP numbers every single byte it sends. The receiver acknowledges whatever's arrived, and the sender retransmits anything that doesn't get acknowledged in time. Segments get reassembled in order before the application ever sees them, which is why a web server or SSH session experiences a clean, gap-free stream.

Flow control and congestion control

The receiver advertises a window — how much data it can actually buffer — so a fast sender can't overwhelm a slow receiver. Separately, congestion control algorithms rein the sender in whenever packet loss or rising delay hints that the network path is overloaded. That's exactly why a large download starts slow and only ramps up afterward.

Closing a connection

Either side can end its half of the connection with a FIN, which the other side then acknowledges. An RST, by contrast, aborts things immediately — it's also what you get back when you connect to a port where nothing's listening.

How UDP works

UDP barely adds anything on top of IP: a source port, destination port, length and checksum, and that's about it. An application hands UDP a message, UDP ships it off as one datagram, and that's the end of UDP's involvement in the matter. No handshake, no acknowledgement, no retransmission. If ordering or reliability actually matters to the application, it has to build that itself.

And that minimalism is precisely the point. A UDP query can get answered in a single round trip, there's no per-connection state sitting on the server, and a late packet never holds up the ones right behind it.

Why games, calls and DNS prefer UDP

  • Stale data is worthless. Think about a video call or a multiplayer game: a packet arriving 300 ms late isn't useful, it's just noise. TCP would freeze the whole stream to go retransmit it. UDP just lets the application skip it and move on to rendering the next frame or position update.
  • No head-of-line blocking. With TCP, one lost segment holds up everything behind it until it's resent. UDP-based protocols can keep independent streams genuinely independent.
  • Small request-response exchanges. A DNS lookup fits in a single packet each way — a TCP handshake would at least double the time per query for no real benefit.
  • Broadcast. DHCP has to reach a server before the client even has an address, and that requires broadcast — something TCP simply can't do.

When UDP traffic switches to TCP

DNS is the textbook dual-protocol service. Queries normally go over UDP port 53, but if the answer turns out too large, the server sets the truncation (TC) flag and the client retries over TCP port 53 instead. Zone transfers lean on TCP too, and RFC 7766 actually requires DNS software to support it. So blocking TCP 53 on a firewall, seemingly harmless, causes subtle DNS failures down the line.

QUIC: reliability built on UDP

QUIC (RFC 9000) is a transport that runs on top of UDP yet still delivers reliable, encrypted, multiplexed streams. It folds the transport and TLS handshakes into one, and a lost packet only stalls the single stream it belongs to, not everything else. HTTP/3 (RFC 9114) runs over QUIC on UDP port 443, so a modern browser loading a page might well be using UDP for the page itself — falling back to TCP 443 only if UDP gets blocked.

Common ports by protocol

Port numbers are 16-bit, running from 0 to 65535, and here's a detail that trips people up: TCP port 53 and UDP port 53 are two entirely separate ports. A few well-known assignments:

PortProtocolService
22TCPSSH
25, 587TCPSMTP mail transfer and submission
53UDP and TCPDNS
67, 68UDPDHCP server and client
80TCPHTTP
123UDPNTP time sync
443TCP and UDPHTTPS (TCP) and HTTP/3 over QUIC (UDP)
500, 4500UDPIPsec IKE and NAT traversal
3389TCP and UDPRemote Desktop
3478UDP and TCPSTUN/TURN for WebRTC calls
51820UDPWireGuard (default)

For a longer list, see our reference of common network ports. When you forward a port or write a firewall rule, make sure you pick the protocol the service actually uses — a TCP-only rule won't do a thing for a game server listening on UDP.

Checking TCP and UDP ports

See what is listening locally

# Linux: TCP and UDP listeners with the owning process
sudo ss -tulpn

# macOS
sudo lsof -nP -iTCP -sTCP:LISTEN
sudo lsof -nP -iUDP

# Windows (PowerShell)
Get-NetTCPConnection -State Listen
Get-NetUDPEndpoint

Test a remote port

# TCP: succeeds only if the handshake completes
nc -vz example.com 443
Test-NetConnection example.com -Port 443     # Windows PowerShell

# UDP: much less conclusive
nc -vzu 198.51.100.10 53

Testing TCP is the easy case: the handshake either completes (open), gets an RST back (closed), or gets no answer at all (filtered). UDP has no handshake to speak of, so an open port will often just sit there silent unless the probe happens to be a valid request for that service. A closed UDP port might return an ICMP "port unreachable" message — or it might not, since firewalls frequently suppress it. That's why most online tools, ours included, our open port checker, stick to testing TCP only. Want to test a UDP service properly? Use the application itself — a dig query for DNS, say, or the game client for a game server.

Tip: Ping, by the way, is neither TCP nor UDP. It rides on ICMP echo messages, so a host can happily answer ping while every single port is closed, or block ping entirely while its web server works just fine. Our ping test measures reachability and latency — not whether some specific service is actually up.

Frequently asked questions

Is UDP faster than TCP?

UDP carries lower overhead and no setup delay, so the first bit of data arrives sooner and late packets never hold up the ones behind them. On a clean link doing bulk transfers, though, TCP achieves much the same throughput. The real difference shows up in latency behaviour under packet loss — it's not really about raw bandwidth.

Is UDP less secure than TCP?

Neither one encrypts anything on its own; that job belongs to TLS, DTLS, QUIC or a VPN. UDP is easier to spoof, though, since there's no handshake to confirm the sender's address in the first place — which is exactly why open UDP services, misconfigured DNS or NTP servers for instance, get abused for reflection attacks.

Can a port use TCP and UDP at the same time?

Yes, absolutely. TCP and UDP keep separate port spaces, so one program can listen on TCP 53 while another — or even the same one — listens on UDP 53 at the same time.

Should I choose TCP or UDP for my VPN?

Go with UDP whenever it works. Tunnel TCP traffic inside a TCP tunnel and you stack two sets of retransmission timers on top of each other, which can tank throughput badly on lossy links. Save TCP mode for networks that actually block UDP.

Essayez vous-même

Mettez ce guide en pratique avec nos outils gratuits.

Commentaires

Partagez une astuce, posez une question ou racontez comment l’outil a fonctionné pour vous.

À lire aussi

Copié dans le presse-papiers