Octonote AI
Make your own →

Note

TCP vs UDP — cheat sheet

Sunil Tiwari· Oct 12, 2026 · 5 min

TCP and UDP are the two transport protocols almost everything on the internet runs on. Both sit on top of IP, which delivers packets on a best-effort basis: they can be dropped, duplicated or arrive out of order. The difference is how much of that mess each protocol hides from your application.

Rule of thumb: TCP for correctness, UDP for timeliness.
TCP and UDP side by side
TCP and UDP side by side

At a glance

TCPUDP
ConnectionHandshake before any dataNone, just send
DeliveryGuaranteed, or the connection failsBest effort, may be lost
OrderBytes arrive in the order sentDatagrams may arrive in any order
Unit of dataA continuous byte streamSeparate datagrams, boundaries kept
Flow and congestion controlBuilt inNone, the app must behave
Header size20 to 60 bytes8 bytes
Latency to first byteAt least one round trip for the handshakeZero extra round trips
One-to-many (broadcast, multicast)NoYes
Typical usesWeb (HTTP/1.1, HTTP/2), SSH, email, databasesDNS, voice and video calls, games, QUIC (HTTP/3)

TCP: a reliable byte stream

TCP gives each side the illusion of a pipe: write bytes in at one end, read the same bytes out at the other, in order, with nothing missing.

  • Three-way handshake. SYN, SYN-ACK, ACK. Both sides agree on starting sequence numbers before any data moves.
  • Sequence numbers and acknowledgements. Every byte is numbered. The receiver acknowledges what it has, and the sender retransmits anything that goes unacknowledged.
  • Fast retransmit. Three duplicate ACKs for the same byte tell the sender a segment was lost, so it resends without waiting for the timer.
  • Flow control. The receiver advertises how much buffer space it has, so a fast sender cannot overwhelm a slow reader.
  • Congestion control. The sender ramps up gradually and backs off when packets are lost, so the network as a whole stays usable.
  • Orderly teardown. Each side sends FIN to close its direction. The side that closes first waits in TIME_WAIT so stray packets from the old connection cannot confuse a new one.
A TCP connection from hello to goodbye
A TCP connection from hello to goodbye

The price is latency. The handshake costs a full round trip before the first byte of data, and TLS adds more on top. If one segment is lost, every byte behind it waits until the retransmission arrives, even if those later bytes belong to unrelated requests. That stall is called head-of-line blocking.

UDP: datagrams and nothing more

UDP adds almost nothing to IP: source and destination ports, a length and a checksum. Each send becomes one datagram that either arrives whole or not at all.

  • No handshake. The first packet already carries data.
  • No retransmission. If a datagram is lost, it is gone unless the application asks again.
  • No ordering. Datagrams can overtake each other on the way.
  • Message boundaries are kept. One send equals one receive, unlike TCP where two writes can arrive as one read.
UDP: fire and forget
UDP: fire and forget

That is exactly what real-time traffic wants. In a video call, a voice packet that arrives 300 ms late is useless, so retransmitting it would only delay the packets that still matter. The app conceals the gap and moves on.

QUIC: the best of both

QUIC, the transport under HTTP/3, runs over UDP and rebuilds what it needs in user space:

  • Reliable, ordered delivery per stream, so one lost packet stalls only the stream it belongs to.
  • TLS 1.3 built in, with a combined handshake that usually needs one round trip, and zero on resumption.
  • Connections survive network changes, such as a phone moving from Wi-Fi to mobile data.

It uses UDP not because it wants unreliability, but because UDP is the only thing middleboxes on the internet will reliably pass through besides TCP.

Which one should I use?

Which one should I use?
Which one should I use?

Pick UDP when…

  • Late data is worse than lost data (voice, video, live games)
  • Messages are tiny and fit in one packet (DNS, telemetry, service discovery)
  • You need broadcast or multicast
  • You need reliable, ordered bytes (file transfer, APIs, databases)

Pick TCP when…

  • Every byte must arrive, in order
  • You want the OS to handle retries, pacing and congestion for you
  • You are speaking an existing TCP protocol (HTTP/1.1, HTTP/2, SSH, SMTP, Postgres)

Common misconceptions

  • "UDP is faster." Per packet, barely. The real win is no handshake and no waiting for retransmissions. On a clean network, TCP throughput is excellent.
  • "TCP guarantees delivery." It guarantees that you will either get the bytes in order or learn the connection broke. It cannot make an unreachable host reachable.
  • "A TCP read returns one message." TCP has no messages. Your protocol needs its own framing, such as a length prefix or a delimiter.
  • "UDP means unreliable apps." Many reliable systems run on UDP and add exactly the reliability they need. QUIC is the most widely deployed example.
Was this useful?
Written bySunil Tiwari
Make a page like this. Free.Notes and diagrams side by side, written by you or by Claude Code and Codex. Publish it in one click.
Make your own, free