How does TCP detect and recover from a lost packet?
The sender retransmits when its timer expires without an ACK, or sooner if it receives three duplicate ACKs, which signal that later segments arrived but one is missing. That second path is called fast retransmit.
Explain it simply
You are sending numbered pages of notes to a friend. They reply "got up to page 4" again and again as pages 6, 7 and 8 arrive. You realise page 5 is lost and resend only it, without waiting for a long timeout.
Example
Sender sends seq 1000, 2000, 3000 (segment 2000 is lost)
Receiver gets 1000 -> ACK 2000
Receiver gets 3000 -> ACK 2000 (duplicate #1: still wants 2000)
Receiver gets 4000 -> ACK 2000 (duplicate #2)
Receiver gets 5000 -> ACK 2000 (duplicate #3)
Sender: three duplicates -> retransmit 2000 now, no timer wait
Receiver: ACK 6000 (everything up to 5999 received)Without duplicate ACKs, the sender must wait for the retransmission timeout, which is calculated from measured round trip times and is usually much longer. Fast retransmit typically also halves cwnd rather than resetting it to 1, because duplicate ACKs prove that packets are still getting through. Modern TCP also uses selective acknowledgements (SACK), which tell the sender exactly which ranges arrived.
What to say in the interview
"TCP uses sequence numbers and ACKs. Loss is detected by a retransmission timeout or by three duplicate ACKs, which triggers fast retransmit. SACK improves this by reporting received ranges. Loss also tells TCP to slow down."
Common mistakes
- Thinking every loss restarts the window from 1. Only a timeout does that in classic TCP.