
The TCP/IP Guide - Version 3.0 (Contents) ` 877 _ © 2001-2005 Charles M. Kozierok. All Rights Reserved.
connection and again used a starting sequence number of 1. As soon as this new
connection was started, however, the old segment with bytes labeled 1 to 30 showed up.
The other device would erroneously think those bytes were part of the new connection.
This is but one of several similar problems that can occur. To avoid them, each TCP device,
at the time a connection is initiated, chooses a 32-bit initial sequence number (ISN) for the
connection. Each device has its own ISN, and they will normally not be the same.
Selecting the Initial Sequence Number
Traditionally, each device chose the ISN by making use of a timed counter, like a clock of
sorts, that was incremented every 4 microseconds. This counter was initialized when TCP
started up and then its value increased by 1 every 4 microseconds until it reached the
largest 32-bit value possible (4,294,967,295) at which point it “wrapped around” to 0 and
resumed incrementing. Any time a new connection is set up, the ISN was taken from the
current value of this timer. Since it takes over 4 hours to count from 0 to 4,294,967,295 at 4
microseconds per increment, this virtually assured that each connection will not conflict with
any previous ones.
One issue with this method is that it makes ISNs predictable. A malicious person could write
code to analyze ISNs and then predict the ISN of a subsequent TCP connection based on
the ISNs used in earlier ones. This represents a security risk, which has been exploited in
the past (such as in the case of the famous Mitnick attack). To defeat this, implementations
now use a random number in their ISN selection process.
TCP Sequence Number Synchronization
Once each device has chosen its ISN, it sends this value to the other device in the
Sequence Number field in its initial SYN message. The device receiving the SYN responds
with an ACK message acknowledging the SYN (which may also contain its own SYN, as in
step #2 of the three-way handshake). In the ACK message, the Acknowledgment Number
field is set to the value of the ISN received from the other device plus one. This represents
the next sequence number the device expects to receive from its peer; the ISN actually thus
represents the sequence number of the last byte received (fictitious in this case, since the
connection is new and nothing yet has been received). We'll see later on that this is
consistent with how these two fields are used for normal data exchange.
Key Concept: As part of the process of connection establishment, each of the two
devices in a TCP connection informs the other of the sequence number it plans to
use for its first data transmission by putting the preceding sequence number in the
Sequence Number field of its SYN message. The other device confirms this by incre-
menting that value and putting it into the Acknowledgment Number field of its ACK, telling
the other device that is the sequence number it is expecting for the first data transmission.
This process is called sequence number synchronization.