Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / Networking 2: TCP, UDP and Ports

    How TCP Keeps Its Promise

    Sequence number — the number of the first byte in each segment (bytes are numbered, not packets).

    Chapter 6 of 124 min read

    The Plain Picture#

    Back to the numbered parcels. The receiver keeps phoning: "I've got everything up to parcel 12." If the sender hears "up to 12" three times while it has already sent 13, 14, 15, 16, it realises parcel 13 went missing and sends it again. If it hears nothing at all for a while, it assumes the worst and resends.

    The Real Names#

    • Sequence number — the number of the first byte in each segment (bytes are numbered, not packets).

    • ACK (acknowledgement) — "I have received every byte before number n." These are cumulative: one ACK confirms everything before it.

    • Retransmission — resending data that wasn't acknowledged.

    • Retransmission timeout (RTO) — how long to wait for an ACK before resending. TCP keeps measuring the real RTT and sets the timeout a little above it.

    • Fast retransmit — resending as soon as three duplicate ACKs arrive, without waiting for the timeout.

    Under the Hood#

    A lost segment, repaired#

    Each segment below carries 1,000 bytes.

       Sender                                              Receiver
         │ ── seq=1001 (bytes 1001–2000) ───────────────────▶ │  ack=2001
         │ ── seq=2001 (bytes 2001–3000) ───── ✗ LOST         │
         │ ── seq=3001 ─────────────────────────────────────▶ │  "still missing 2001" → ack=2001 (dup)
         │ ── seq=4001 ─────────────────────────────────────▶ │  ack=2001 (dup)
         │ ── seq=5001 ─────────────────────────────────────▶ │  ack=2001 (dup #3)
         │                                                    │
         │  3 duplicate ACKs → resend 2001 immediately        │
         │ ── seq=2001 (resent) ────────────────────────────▶ │  now has 1001–6000 → ack=6001

    Notice: the receiver held on to segments 3001–5000 but couldn't give them to the program yet, because byte 2001 was missing and TCP promises order. That waiting is important for Ch 9.

    How each promise is kept#

    PromiseMechanism
    Ordersequence numbers; the receiver re-sorts and waits for gaps
    No lossACKs + retransmission (timeout or 3 duplicate ACKs)
    No duplicatesthe receiver drops bytes whose sequence numbers it already has
    No corruptiona checksum in each segment; corrupted ones are dropped and later resent

    Gotchas

    • Reliability has a limit. If the network is down long enough, TCP gives up and the program gets an error. "Reliable" means "you'll either get the data correctly, or an error" — never silent loss.

    • TCP can't know if the program processed your data. An ACK means the other kernel received the bytes — not that the server saved Priya's note to the database. If the server crashes after the ACK, the data is lost. Application-level confirmations (and idempotency, How Web APIs Work (coming soon)) handle that.

    Check yourself

    4 questions
    1

    What does "ack = 7001" mean?

    Show answer

    "I have every byte up to 7000; send 7001 next."

    2

    What are the two ways TCP decides to resend?

    Show answer

    A retransmission timeout, or three duplicate ACKs (fast retransmit).

    3

    Why can't the receiver hand segments 3001–5000 to the program while 2001 is missing?

    Show answer

    TCP promises in-order delivery, so it must wait for the gap to be filled.

    4

    Does a TCP ACK mean the server's program has handled your data?

    Show answer

    No — only that the server's kernel received the bytes.