L3 · NetworksNetworking 101 · part 3 of 7

TCP vs UDP, and Why It Matters

One protocol makes sure every byte arrives, the other gets data there fast, and choosing between them affects everything from games to QUIC.

Takumi Yamada
· 6 min read · 3 references
networkingtcpudpquicprotocols

IP (Internet Protocol) moves towards their destination, and promises nothing else. A packet can be lost, arrive twice, or arrive after packets that were sent later.

The transport layer sits on top of IP and decides what to do about that. It offers two choices. TCP (Transmission Control Protocol) makes delivery reliable and in order, and that costs some time. UDP (User Datagram Protocol) adds almost nothing, and stays fast.

is often treated as the normal choice and as the unusual one. I think choosing between them is a real engineering decision, and the newest are built on UDP.

The core trade-off

TCPUDP
ConnectionYes, with a None
DeliveryGuaranteed and retransmittedBest effort, may drop
OrderingIn orderWhatever arrives
Flow and congestion controlYesNo, you build it
overhead20 or more8 bytes
FeelA phone callPostcards

TCP is like a phone call. You connect first, and then everything you say arrives in order. It gives your program a stream of bytes and deals with lost or out-of-order packets for you. UDP is like sending postcards. Each one travels alone, and some may never arrive. UDP adds only a small header to each packet, with the sender's port, the receiver's port, the length and a checksum, a number used to detect damaged data. Everything else is up to you.

UDP8 bytessrc portdst portlengthchecksum02468four fields,and that is all of itTCP20 bytes or moresequence numbers, acknowledgments, a window, and more048121620
Both headers to scale, with a byte ruler under each.

TCP's three way handshake

Before any data is sent, TCP sets up a connection, and both sides agree on their starting sequence numbers.

DATADATATCPa handshake firstCLIENTSERVERSYN seq=xSYN-ACK seq=y, ack=x+1ACK ack=y+1your dataone round trip before any dataUDPnothing to set upCLIENTSERVERdatagram 1datagram 2datagram 3datagram 4lostdata from the first packet, no promises
The same client and server over each protocol. The outlined span is where data is flowing.

That costs one full round trip, the time for a message to go there and back, before any of your data moves. For a short exchange, that's pure delay. For a long one, it's the price of reliability.

The sequence numbers are what let TCP notice a lost packet and put packets back in order. They also let both sides agree on where the stream starts.

How TCP keeps it reliable

Every byte has a sequence number. The receiver sends back acknowledgments, which say what it has received. If the sender gets no acknowledgment within a certain time, or gets the same acknowledgment several times, it sends the data again. That's called retransmitting.

SENDERRECEIVERbytes 1 to 100ack 100bytes 101 to 200bytes 101 to 200, againack 200every byte is numbered,and the receiver sayshow far it has gotno acknowledgment arrivesbefore the timeout,so it is sent again
One lost segment and its retransmission.

Two more mechanisms work on top of that.

Flow control protects a slow receiver. The receiver keeps telling the sender how much free space it has, which is called the window. The sender never sends more than that, so the receiver's buffer never overflows.

SENDERTHE RECEIVER'S BUFFER, 1000 BYTESwindow = 400at most 400 more bytes600 bytes received,not read by the app yet400 bytes free
Flow control. The window is the free space in the receiver's buffer.

Congestion control protects the network. The sender raises its sending rate slowly to find out how much the network can carry, and lowers it when packets get lost. This stops many TCP connections from overloading a shared link. Algorithms such as CUBIC and BBR do this work.

sending ratetimewhat the link can carrya packet is lost,the rate is cutbetween losses the rate is raised a step at a time
Congestion control. The sender raises its rate until a packet is lost, cuts the rate, and starts raising it again.

All of this happens automatically. You write bytes, and they arrive in order.

Head-of-line blocking: TCP's hidden cost

Here is a less obvious problem, and the rest of this post is about it.

TCP delivers bytes strictly in order. Suppose packet 5 is lost, and packets 6, 7 and 8 have already arrived. TCP won't give any of them to your program until packet 5 has been sent again and received. Everything waits behind the missing packet.

TCPone ordered stream12345678LOSTdelivered to the apparrived, but held until 5 is resentQUICa stream eachstream A147stream B258stream C36only stream Bwaits for 5
lose packet
TCP holds back 3 packets, QUIC 1
Eight packets, and one is lost: number 5 to begin with. TCP holds back everything behind it. QUIC, covered below, deals the same packets to separate streams, so only the stream that lost one waits. Lose a different packet with the buttons and compare how much each one holds back.

This is called head-of-line blocking, after a queue where the person at the front holds up everyone behind them.

For downloading one file, it doesn't matter. But some programs send many separate messages and need each one quickly. For them, it's a serious problem, because one lost packet holds up everything behind it, including data that has nothing to do with it.

When UDP wins

Sometimes data is only useful for a short time, and losing a little of it is acceptable. Then waiting for a resend is worse than moving on, because by the time the resent packet arrives, it's already out of date.

Online games. A player's position from 50 milliseconds ago is useless. You want the next update, not the old one sent again.

UDPuse what arrives1234lost, skippedshown at onceTCPwait for the resend123234lostarrived, held back2 resent, 3 shown late0 ms50 ms100 ms150 ms
A game sending its position every 50 ms. Over TCP, the resend of update 2 delays update 3, which had already arrived.

Live voice and video. Skip the lost frame, hide the gap, and continue. A short glitch is better than a frozen picture.

DNS (Domain Name System). It's one tiny question and one tiny answer. A TCP handshake would double the wait for no benefit.

With UDP you can build exactly the reliability you need and skip the rest. Here is a minimal UDP in Go. Notice that there is no connection to accept, only packets to read.

addr, _ := net.ResolveUDPAddr("udp", ":9000")
conn, _ := net.ListenUDP("udp", addr)
defer conn.Close()

buf := make([]byte, 1500) // about one Ethernet MTU
for {
    n, from, err := conn.ReadFromUDP(buf)
    if err != nil {
        continue
    }
    // each read is one independent datagram: no stream, no ordering
    handle(buf[:n], from)
}

Each read returns one complete datagram, which is what a UDP packet is called. There is no stream that could get stuck. That independence is the reason to use UDP.

QUIC: having it both ways

The downside of UDP used to be that you lost reliability completely. QUIC (Quick UDP Internet Connections) solves that. It's the transport underneath (Hypertext Transfer Protocol)/3.

QUIC runs on top of UDP, but rebuilds reliability, ordering and congestion control inside the program itself. That gives two big advantages.

No head-of-line blocking between streams. QUIC carries several separate streams over one connection. A lost packet only holds up its own stream, and the others carry on. This was the biggest weakness of HTTP/2, which put all its streams on one TCP connection, so one lost packet stopped all of them.

Faster setup. QUIC combines its own handshake with the (Transport Layer Security) handshake. It often has an encrypted connection ready after one round trip, or after none when reconnecting to a server it knows. TCP plus TLS needs two.

REQUESTREQUESTTCP + TLS 1.3BROWSERSERVERSYNSYN-ACKACK, hello, keyshello, keys, certificateGET /two round trips before the requestQUICBROWSERSERVERhello, keyshello, keys, certificateGET /one round trip before the request
The first request over TCP with TLS 1.3, and over QUIC. The outlined span is the request itself.

Because QUIC runs inside programs on top of UDP, it can be improved without waiting for and network equipment to be updated. TCP can't do that, because it's built into the operating system and inspected by equipment along the way.

The HTTP side of this, from six connections per site to streams over QUIC, has its own post, HTTP/2 and HTTP/3: Same Requests, Different Wire.

The pattern is to start with UDP, which promises nothing, and add back only the promises you need. That's why the newest protocols are built on UDP rather than on TCP.

How to choose

Do you need every byte, in order, and can you accept one round trip to set up? Use TCP. That covers web pages, , file transfers, (Secure Shell) and .

Do you need the lowest delay, can you accept some loss, or do you want to build your own reliability? Use UDP. That covers games, live audio and video, and .

Do you want several reliable streams with low delay and no head-of-line blocking? Use QUIC, which is UDP underneath with reliability added on top.

Knowing the trade-off lets you choose the right protocol. You don't pay for promises you don't need, and you don't find out in production that you needed them.

Check yourself

3 questions · nothing is saved
  1. 1.Packet 5 is lost, and packets 6, 7 and 8 have already arrived. What does TCP hand to your program?
  2. 2.Why do online games often use UDP?
  3. 3.What does QUIC fix compared with HTTP/2 over TCP?

References & Primary Sources

Official specifications, standards, and documentation cited in this post.

  1. [1]

    DARPA Internet Program Protocol Specification defining connection establishment, reliability, and flow control

    RFCrfc-editor.org
  2. [2]

    The original minimal datagram protocol specification

    RFCrfc-editor.org
  3. [3]

    Modern replacement for TCP implementing congestion control in userspace

    RFCrfc-editor.org

Who wrote this

Author profile and background

Takumi Yamada

Takumi Yamada

· Backend Engineer

Backend engineer building services, databases, Linux tooling, and NEGEN SYSTEMS. Writing about low-level mechanics, distributed systems, and real-world security.

End of post
NEGEN SYSTEMS
Receipt · post 4 of 31
Written
Nov 9, 2025
Length
1,219 words · 6 min
Built
…
Served by
…
Delivered
…
Over the wire
…
Go's share
…
Next in Networking 101 · part 4 of 7

HTTP/2 and HTTP/3: Same Requests, Different Wire

A GET request still means the same thing. What changed twice is how it travels: HTTP/2 put every request on one TCP connection, and HTTP/3 moved everything onto QUIC to fix the one problem HTTP/2 couldn't.

10 min read