Transmission Control Protocol accepts data from a stream, divides it into small chunks, and adds a TCP header creating a TCP segment. The TCP segment is encapsulated into an Internet Protocol datagram (IP datagram); and exchanged with peers.
These TCP segments possibly will arrive at their destination out-of-order. For understanding, the original message to the receiver, the data in these out-of-order segments are reassembled to the correct order. Each segments header has assigned a sequence number to get this goal. The sequence number represents the first data byte of the TCP segment.
During the established session, the first sequence number (ISN); is set. This ISN represents the opening value of the bytes for this session which is transmitting to the receiving side application. When data is transmitting during the established session. The sequence number is increasing by the number of transmitted bytes. This data byte tracking enables every segment to individually find and acknowledged. The missing segments can identify and also reported. The ISN is effectively a random number. This is to avoid certain types of malicious attacks. For simplicity, we will use an ISN of 1 for the examples. sequence numbers also show how to reassemble and reorder received segments, as shown in the figure.
The receiving TCP process places the data from a segment into a receiving buffer. Segments are in the proper sequence order and passed to the application layer when reassembled. Wrong order sequence number remains hold for later processing. if, when the segments with the missing bytes reach the destination, these segments processed in proper order.