Overview

TCP and UDP are the two core transport-layer protocols used to move data between hosts, but they trade reliability for speed in opposite directions. TCP prioritizes reliable delivery through handshakes, acknowledgments, and retransmission, while UDP prioritizes low-latency delivery by sending datagrams with no setup or delivery guarantees. Choosing between them shapes how an application handles packet loss, ordering, and throughput.

Comparison Diagram

TCPUDPClientServerSenderReceiverSYNSYN-ACKACKconnection establishedDataACKDataACKFIN / ACK teardownDatagramDatagramlost, no retryDatagramDatagramno ACKs, no ordering

Comparison Table

AspectTCPUDP
Connection setupThree-way handshake (SYN, SYN-ACK, ACK) establishes a stateful connection before any data movesNo handshake — sender transmits datagrams immediately with no prior negotiation
Delivery guaranteeGuaranteed via sequence numbers and acknowledgments; lost segments are detected and resentBest-effort only; lost packets vanish silently with no notification to either side
OrderingSegments are reassembled in the original order regardless of arrival sequenceNo ordering guarantee; packets are delivered to the application in whatever order they arrive
Flow & congestion controlDynamic window sizing and congestion-avoidance algorithms throttle the sender to match network capacityNone; the application sends at whatever rate it chooses, independent of network conditions
Error handlingChecksum plus automatic retransmission recovers corrupted or missing segmentsChecksum only; corrupted or missing packets are simply dropped, not recovered
Overhead & latencyLarger 20+ byte header and handshake/ACK round trips add processing and latencyMinimal 8-byte header and no round trips keep per-packet overhead and latency low
Connection teardownExplicit four-way FIN/ACK exchange formally closes the connection on both sidesNo connection state exists, so transmission simply stops with nothing to tear down

Key Differences

  • TCP is connection-oriented, requiring a handshake before data flows, while UDP is connectionless
  • TCP guarantees reliable delivery through acknowledgments and retransmission; UDP offers none
  • TCP performs congestion control to avoid overwhelming the network; UDP has no such mechanism
  • UDP’s minimal header overhead gives it consistently lower latency than TCP
  • TCP preserves packet ordering end-to-end; UDP delivers packets in whatever order they arrive

When to Use Each

TCP

  • Web & API traffic (HTTP/HTTPS): Requests and responses must arrive complete and in order, making TCP’s reliability essential
  • File transfer (FTP, SFTP): Every byte must arrive intact, so retransmission of lost segments is worth the added latency
  • Database connections: Queries and results demand guaranteed, ordered delivery to keep transactions consistent
  • Email transmission (SMTP): Message integrity matters more than speed, favoring TCP’s reliability guarantees

UDP

  • DNS lookups: A single small request/response benefits from UDP’s low overhead, with the application retrying on its own if needed
  • Live video & voice calls: A dropped frame is preferable to the added latency of waiting for retransmission
  • Online multiplayer gaming: Stale position data is worthless, so UDP’s speed matters more than guaranteed delivery
  • IoT sensor telemetry: High-frequency readings can tolerate occasional loss, and UDP’s low overhead suits constrained devices