Skip to content

02-01: Exercises

Question

A client initiates a TCP connection to a web server.

  • The client's Initial Sequence Number (ISN) is 5000.
  • The server's Initial Sequence Number (ISN) is 9000.

Answer the following:

  1. What SEQ and ACK numbers appear in the SYN packet (client → server)?
  2. What SEQ and ACK numbers appear in the SYN-ACK packet (server → client)?
  3. What SEQ and ACK numbers appear in the final ACK packet (client → server) that completes the handshake?
  4. After the handshake, the client sends a data packet carrying 200 bytes of payload. What SEQ number does this packet use, and what ACK number will the server send back to acknowledge it?

Solution

Step 1: The SYN packet (client → server)

The client starts the handshake by sending its ISN. No data has been sent yet, and there is nothing to acknowledge, so there is no ACK number.

  • SEQ = client's ISN = 5000
  • ACK = none (ACK flag not set yet)
  • Flags = SYN

👉 (1) SYN packet → SEQ = 5000, ACK = none, Flags = SYN


Step 2: The SYN-ACK packet (server → client)

The server replies with its own ISN in the SEQ field, and acknowledges the client's SYN.

Rule: a SYN flag consumes 1 sequence number, even though it carries no data. So the ACK number equals the sender's received SEQ + 1.

  • SEQ = server's ISN = 9000
  • ACK = client's SEQ + 1 = 5000 + 1 = 5001
  • Flags = SYN, ACK

👉 (2) SYN-ACK packet → SEQ = 9000, ACK = 5001, Flags = SYN, ACK


Step 3: The final ACK packet (client → server)

The client now acknowledges the server's SYN. The client's own SEQ number moves forward by 1 because its SYN also consumed a sequence number in Step 1.

  • SEQ = client's previous SEQ + 1 = 5000 + 1 = 5001
  • ACK = server's SEQ + 1 = 9000 + 1 = 9001
  • Flags = ACK

👉 (3) Final ACK packet → SEQ = 5001, ACK = 9001, Flags = ACK

The three-way handshake is now complete:

Step Direction Flags SEQ ACK
1 Client → Server SYN 5000
2 Server → Client SYN, ACK 9000 5001
3 Client → Server ACK 5001 9001

Step 4: Client sends 200 bytes of data

After the handshake, the client's next SEQ number is exactly where it left off in Step 3 — 5001 — because a plain ACK with no data does not consume a sequence number, only SYN and FIN flags do.

  • Data packet SEQ = 5001
  • The payload occupies sequence numbers 5001 through 5200 (200 bytes).

The server then acknowledges by pointing to the next byte it expects:

  • ACK = data SEQ + number of bytes received = 5001 + 200 = 5201
  • The server's own SEQ stays at 9001 (it hasn't sent any new data of its own).

👉 (4) Data packet → SEQ = 5001, 200 bytes of payload. Server's ACK in response → ACK = 5201, SEQ = 9001


Final Answer

Packet Direction Flags SEQ ACK
1. SYN Client → Server SYN 5000
2. SYN-ACK Server → Client SYN, ACK 9000 5001
3. ACK Client → Server ACK 5001 9001
4. Data (200 bytes) Client → Server ACK 5001 9001
5. Server's ACK of data Server → Client ACK 9001 5201

Key rule used throughout: ACK number = other side's SEQ + number of bytes received, where SYN and FIN flags each count as 1 "byte" even though they carry no payload.