Skip to main content

Command Palette

Search for a command to run...

Reliable Connection in TCP : How sequence numbers and ACKs work

Published
3 min read

When you browse the web, stream a video, or download a file, you probably don’t think about what’s happening behind the scenes. Yet, one reason the internet feels seamless is TCP (Transmission Control Protocol). Unlike faster but unreliable protocols like UDP, TCP ensures your data arrives in the right order, without errors. It achieves this using sequence numbers and acknowledgments (ACKs).

1. Why Reliability Matters in TCP

Imagine downloading a large file in chunks. If one chunk goes missing or arrives out of order, the file becomes corrupted. TCP prevents this by:

  • Tracking every piece of data with sequence numbers.

  • Confirming delivery with ACKs (acknowledgments).

  • Retransmitting lost data when necessary.

This reliability makes TCP the backbone of most internet applications — web browsing, email, messaging, and file transfer.

2. Sequence Numbers: The GPS of Data Packets

  • Every byte of data sent over TCP gets a unique sequence number.

  • The first byte in a session has a random starting number (to add security).

  • When data is split into packets, each packet carries the sequence number of its first byte.

👉 Example:
If the first packet carries bytes 1–1000, the next packet will start at 1001, and so on.

This numbering allows the receiver to reassemble data in the correct order, even if packets arrive shuffled.

3. ACKs: The Receiver’s Confirmation Signal

  • After receiving a packet, the receiver sends back an ACK number.

  • The ACK number tells the sender:

    “I’ve successfully received everything up to byte X. Please send the next one.”

👉 Example:
If the receiver got bytes 1–1000, it replies with ACK=1001, signaling it’s ready for the next chunk.

4. What If a Packet Gets Lost?

Here’s where TCP’s reliability shines:

  • If the sender doesn’t receive an ACK in time, it retransmits the missing packet.

  • TCP also uses mechanisms like duplicate ACKs and timeout retransmission to detect and fix losses quickly.

👉 Example:
If packet with bytes 2001–3000 is lost, the receiver won’t send an ACK for 3001. Instead, it keeps asking for 2001 again, until the sender retransmits it.

5. Sliding Window: Efficiency in Action

To avoid sending data one packet at a time, TCP uses a sliding window mechanism:

  • Multiple packets can be sent before waiting for ACKs.

  • Once ACKs are received, the “window” slides forward, and new data can be sent.

This balances speed with reliability.

6. Real-World Analogy

Think of sequence numbers and ACKs like sending pages of a book by courier:

  • Each page is numbered (sequence number).

  • The receiver replies: “I got up to page 25. Send the next.” (ACK).

  • If a page goes missing, the sender resends it.

  • At the end, the receiver has a complete, correctly ordered book.

7. Why This Matters

Without sequence numbers and ACKs:

  • Web pages could load with missing text.

  • Video streams could freeze randomly.

  • File downloads could be corrupted.

Thanks to TCP, the internet feels smooth, reliable, and predictable — no matter how messy the underlying network really is.

Summary:

TCP’s reliability comes from two simple but powerful ideas:

  • Sequence numbers ensure packets arrive in the right order.

  • ACKs confirm delivery and request retransmission when needed.

Together, they form the backbone of modern internet communication.