Course contentsShow
← Computer Science
Lesson 1475 of 2,87234. Internet Protocol SuiteFree lesson

Sequence Numbers and Acknowledgments

How TCP uses sequence numbers to order data and acknowledgments to confirm receipt of bytes.

Sequence Numbers and Acknowledgments

What you'll learn: How TCP ensures every byte of data arrives in order and confirms receipt using sequence numbers and acknowledgments.

The Core Challenge

When TCP sends data across a network, packets can arrive out of order, get duplicated, or even lost. TCP solves this by numbering every byte of data transmitted and explicitly acknowledging what's been received successfully.

How Sequence Numbers Work

Every TCP segment carries a sequence number that identifies the position of its first byte in the data stream. For example, if you send a 1000-byte message, the first segment might have sequence number 1000, the next 2000, and so on.

Think of it like page numbers in a book sent via mail—even if pages arrive out of order, the receiver can reassemble them correctly by looking at the numbers.

When a connection starts (during the three-way handshake), both sides choose an Initial Sequence Number (ISN). From that point forward, every byte sent increments the sequence number.

How Acknowledgments Work

The receiving side sends back acknowledgment numbers (ACKs) to confirm receipt. The ACK number indicates "I've received all bytes up to this number, send me byte X next."

For example, if the receiver gets bytes 1000–2999 successfully, it sends ACK 3000, meaning "I'm ready for byte 3000 now."

This is cumulative acknowledgment—one ACK can confirm multiple segments at once. If segments arrive out of order, TCP buffers them until the missing pieces arrive, then delivers data to the application in correct order.

Why This Matters

This mechanism enables TCP's reliability: if the sender doesn't receive an ACK within a timeout period, it retransmits the data. Sequence numbers prevent duplicates and ensure ordered delivery.

Key Takeaway: TCP uses sequence numbers to label every byte of data and acknowledgment numbers to confirm receipt, enabling reliable, ordered delivery even over unreliable networks.