TCP Sequence Number Calculator
Calculate the next TCP sequence number, expected acknowledgment number, sequence-space consumption, payload byte range and 32-bit wraparound from SEQ, payload length, SYN and FIN flags.
SEQ + payload bytes + SYN + FIN, calculated modulo
2^32. The ACK flag itself consumes no sequence number.
—
—
—
What Is a TCP Sequence Number?
TCP assigns sequence numbers to bytes in its reliable byte stream. The Sequence Number field in the TCP header identifies the sequence-space position associated with the segment.
Sequence numbers are 32 bits wide, so they range from 0 through 4,294,967,295 before wrapping back to zero.
TCP Next Sequence Number Formula
Sequence Space Consumed =
Payload Length
+
SYN
+
FIN
Next SEQ =
(Starting SEQ + Sequence Space Consumed)
mod 2^32SYN and FIN are counted as one sequence-space position each. Other ordinary TCP flags such as ACK, PSH and RST do not add payload sequence bytes by themselves.
TCP Payload Sequence Number Example
Suppose a segment starts with sequence number 1000 and carries 500 bytes with no SYN or FIN.
Starting SEQ:
1000
Payload:
500 bytes
Payload sequence numbers:
1000 through 1499
Next SEQ:
1500
Receiver ACK:
1500Why Does SYN Consume One Sequence Number?
Although SYN is a control flag rather than application payload, TCP assigns it one position in sequence space. This is why the first data byte following an initial SYN normally starts at ISN + 1.
SYN Segment:
SEQ = 1000
SYN = 1
Payload = 0
Next SEQ:
1001
Expected ACK:
1001Why Does FIN Consume One Sequence Number?
FIN also occupies one sequence-space position. A receiver acknowledges the FIN by advancing its acknowledgment number by one after all preceding payload bytes.
SEQ:
5000
Payload:
100 bytes
FIN:
1
Sequence consumption:
100 + 1 = 101
Expected ACK:
5101TCP SYN with Payload
If SYN and payload occur in the same segment, the SYN consumes the first sequence-space position and payload begins immediately after it.
SEQ = 1000
SYN = 1
Payload = 10 bytes
SYN occupies:
1000
Payload occupies:
1001 through 1010
Next SEQ:
1011TCP Sequence Number Wraparound
TCP sequence arithmetic operates in a 32-bit space. When addition exceeds 4,294,967,295, the result wraps modulo 2^32.
Starting SEQ:
4294967290
Payload:
10
Calculation:
4294967290 + 10
= 4294967300
2^32:
4294967296
Wrapped Next SEQ:
4TCP Acknowledgment Number
A TCP acknowledgment number normally identifies the next sequence number the receiver expects from the other endpoint.
Received segment:
SEQ = 2000
Payload = 100 bytes
Bytes received:
2000–2099
Expected ACK:
2100If the segment contains SYN or FIN, their sequence-space consumption must also be included when calculating the acknowledgment.
TCP Sequence Number vs ACK Number
| Field | Meaning |
|---|---|
| Sequence Number | Position of the segment in the sender’s TCP sequence space |
| Acknowledgment Number | Next sequence-space position expected from the peer |
| Payload Length | Number of application-data bytes consuming sequence space |
| SYN | Consumes one sequence number |
| FIN | Consumes one sequence number |
| ACK Flag | Does not itself consume sequence space |
TCP Initial Sequence Number
When a TCP connection begins, each endpoint selects an Initial Sequence Number, or ISN. During the three-way handshake the SYN consumes one position, so the next sequence number used by that endpoint is ISN + 1 modulo 2^32.
TCP Three-Way Handshake Example
Client → Server
SYN
SEQ = 1000
Server expects:
ACK = 1001
Server → Client
SYN, ACK
SEQ = 5000
ACK = 1001
Client expects:
ACK = 5001
Client → Server
ACK
SEQ = 1001
ACK = 5001