How TCP makes sure data arrives

· 2 min read

#how-it-works#networking

TCP numbers the bytes it sends and waits for the receiver to confirm them. The idea to keep: no confirmation in time, so send again.

The short version

Every byte in a TCP connection has a sequence number. The receiver answers with an acknowledgment number, the next byte it expects. The sender keeps data that is not confirmed yet and runs a retransmission timer. If the timer runs out first, it sends the oldest unconfirmed segment again.

How TCP resends data that is not acknowledged A sender sends a segment and checks whether an acknowledgment arrived. If yes, it sends the next data. If no, the retransmission timer runs out, the oldest unacknowledged segment is resent with a doubled timeout, and the loop starts again. Send segment keeps it until ACKed ACK arrived? next byte expected Send next data timer restarts or stops Timer runs out no ACK in time Resend oldest unACKed segment RTO doubled, restart 1 2 yes 3 no 4 5 wait again
RTO is the retransmission timeout: the time the sender waits for an acknowledgment before sending again.

Step by step

  1. The sender numbers its bytes, not its segments. The SYN and FIN flags use up one number each.
  2. The receiver acknowledges the next byte it expects. Acknowledgments are cumulative.
  3. A segment that arrives ahead of the expected number is held and processed later.
  4. The sender keeps unconfirmed data and a timer. An acknowledgment of new data restarts the timer; when everything is acknowledged, it stops.
  5. If the timer expires, the sender resends the oldest unconfirmed segment and restarts the timer with the timeout doubled.

Why it matters

TCP does not need to know why a segment went unconfirmed: a timer running out is enough to try again. That is my reading of the specs, not a quoted line. Simplified: flow control, congestion control and timer values are left out.

Sources