TCP - SEQ and ACK values

During a TCP session, there are several values that exist in the TCP headerthat are used by the sender and receiver to coordinate and manage that session. This starts off with the three way handshake that establishes the session. However, from there on, the Sequence Number (SEQ) and the Acknowledgement Number (ACK) are used to keep track of the session.

Note that there are two SEQ and two ACK numbers that are incremented, one for the sender and one for the receiver. We'll call those SEQs and SEQr, and ACKs and ACKr.

Take a look at these two hosts:

two-computers-1.png

Let's say that the three way handshake has completed, and the Sender begins sending data. Let's say they send initially 10 bytes of data like so:

two-computers-2.png

The receiver will respond with a TCP segment with specific values for its SEQr and ACKr:

For the ACKr value, it will send the next expected byte. To get this value, we must do the following calculation:

ACKr = SEQs + the number of bytes sent = 1 + 10 = 11

So if the sender sent the first 10 bytes, the receiver will send back an ACKr of 11. But it will also send an SEQr. This is independent of the sender's SEQs, and it starts its own sequence numbering. This response is typically small, because it doesn't contain any data, so we'll say that it has a length of 1 Byte. It starts with an SEQr of 1. So here it is:

two-computers-3.png

Now, what will the sender send? Let's say they send another 15 bytes. For the values of the numbers we get:

  • SEQs must be equal to the ACKr it received, so SEQs will be 11
  • ACKs will be the next expected byte. We do a similar calculation as before
    • ACKs = SEQr + the number of bytes received = 1+1 = 2

So the next segment looks like this:

two-computers-4.png

We'll do one more. The receiver receives 15 bytes, so the respond will have these values:

  • SEQr must be equal to the ACKs it received, so SEQr = 2
  • ACKr will be the next expected byte. To get that we do the following calculation:
    • ACKr = SEQs + the number of bytes received =11 + 15 = 26

So 26 is the next expected byte. The response is small once again, so we consider it to be 1 Byte. So the next segment looks like this:

two-computers-5.png

So remember, each host, the sender and the receiver, maintain their own sequence numbers. The SEQ are always equal to the ACK that was received. The ACK that is sent is the next expected byte.

These values are also affected by the TCP window size and the window size scaling that is employed on TCP, since the window size affects the number of bytes sent before an acknowledgement is expected from the receiver.

Links:

https://forum.networklessons.com/t/introduction-to-tcp-and-udp/862/83?u=lagapidis

https://networklessons.com/cisco/ccnp-route/introduction-to-tcp-and-udp

Links to this page: