Перейти к содержимому
Skip to content
← All articles

TCP vs UDP: Differences, Use Cases, and Performance

TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are the two foundational transport-layer protocols of the Internet. Every networked application relies on one or both of them to move data between hosts. Understanding their differences is essential for making informed architectural decisions about reliability, latency, and throughput.

How TCP Works

TCP is a connection-oriented protocol. Before any data is exchanged, the client and server perform a three-way handshake to establish a reliable, stateful connection:

Client → Server: SYN (seq=x)
Server → Client: SYN-ACK (seq=y, ack=x+1)
Client → Server: ACK (ack=y+1)

Once the connection is established, TCP provides several guarantees:

TCP Header Structure

The TCP header is at least 20 bytes and contains fields critical to its reliability mechanisms:

FieldSizePurpose
Source Port16 bitsIdentifies the sending application
Destination Port16 bitsIdentifies the receiving application
Sequence Number32 bitsTracks byte position in the stream
Acknowledgment Number32 bitsNext expected byte from the other side
Window Size16 bitsFlow control — how much data the receiver can accept
Checksum16 bitsError detection for header and data
Flags6 bitsSYN, ACK, FIN, RST, PSH, URG — control connection state

How UDP Works

UDP is a connectionless protocol. There is no handshake — the sender simply transmits datagrams to the destination. The UDP header is only 8 bytes, making it extremely lightweight:

FieldSizePurpose
Source Port16 bitsSending application identifier
Destination Port16 bitsReceiving application identifier
Length16 bitsTotal datagram size
Checksum16 bitsOptional error detection (mandatory in IPv6)

UDP provides no delivery guarantees: packets may arrive out of order, be duplicated, or be lost entirely. This makes it lightweight and fast, but places reliability concerns squarely on the application layer.

Head-to-Head Comparison

FeatureTCPUDP
ConnectionConnection-oriented (3-way handshake)Connectionless
ReliabilityGuaranteed delivery with retransmissionBest-effort, no guarantees
OrderingIn-order deliveryNo ordering
Overhead20+ byte header8 byte header
LatencyHigher (handshake + ACKs)Lower (no setup)
Flow ControlYes (sliding window)No
Congestion ControlYes (built-in algorithms)No
BroadcastingNot supportedSupported (multicast/broadcast)

When to Use TCP

TCP is the right choice when data integrity and completeness matter more than raw speed:

When to Use UDP

UDP excels when speed and low latency outweigh the need for perfect delivery:

Performance Implications for Web Applications

Connection Overhead

A TCP handshake adds one round-trip time (RTT) before data transfer begins. With TLS, this becomes two RTTs (TCP handshake + TLS handshake). On a connection with 100ms RTT, that is 200–300ms of overhead before the first byte of application data.

# Measuring TCP connection time with curl
curl -w "tcp_connect: %{time_connect}s\ntls_handshake: %{time_appconnect}s\nfirst_byte: %{time_starttransfer}s\n" -o /dev/null -s https://example.com

TCP Slow Start and Congestion Windows

New TCP connections begin with a small congestion window (typically 10 segments, about 14KB). This directly affects how quickly a server can push data to a new client. For websites, the critical rendering path should ideally fit within this initial congestion window.

QUIC: The Best of Both Worlds

HTTP/3 uses QUIC, a protocol built on UDP that implements TCP-like reliability at the application layer. QUIC combines the reliability of TCP with the speed advantages of UDP:

Monitoring TCP and UDP Services

When monitoring networked services, understanding the underlying protocol helps diagnose issues efficiently:

# Check TCP connection states
ss -ant | awk '{print $1}' | sort | uniq -c | sort -rn

# Monitor TCP retransmissions
watch -n1 'netstat -s | grep -i retransmit'

# Test UDP port reachability
nc -zuv example.com 53

Summary

TCP and UDP serve fundamentally different needs. TCP provides reliable, ordered data delivery at the cost of higher latency and overhead. UDP offers minimal overhead and low latency without delivery guarantees. Modern protocols like QUIC show that these trade-offs are not binary — by building reliability on top of UDP, it is possible to achieve the best characteristics of both. When designing or monitoring networked applications, choosing the right transport protocol is one of the most impactful architectural decisions you can make.

Check your website right now

Check now →
More articles: Networking
Networking
IP Geolocation Accuracy: How It Works and Where It Fails
11.03.2026 · 11 views
Networking
TCP Connection Tuning: Keepalive, Window Size, and Nagle's Algorithm
16.03.2026 · 14 views
Networking
IPv4 vs IPv6: Differences, Migration, and What It Means for Your Website
16.03.2026 · 9 views