Open In App

Wrap Around Concept and TCP Sequence Number

Last Updated : 11 Jul, 2025
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

TCP is a core protocol of the Internet protocol suite. It provides reliable, full transport-layer services to applications by establishing a virtual connection between the sender and receiver for the duration of data transmission.

How TCP Works:

  • TCP receives continuous data from the application layer.
  • It breaks the data into manageable chunks, each containing a series of bytes.
  • Each chunk is then wrapped with a TCP header to form a TCP segment.

Structure of a TCP Segment:

  • TCP Header: Contains control information like source and destination ports, sequence numbers, etc.
  • TCP Options: Optional fields that can be used for features like window scaling.
  • Data: The actual payload being transmitted.

Read more about TCP

TCP Sequence Number

Each TCP segment sent by the sender includes a portion of data. TCP assigns a unique sequence number to each byte in the data stream. This number is essential for tracking and managing data during transmission.

Purpose of Sequence Numbers

  • Identifies each byte of data uniquely.
  • Helps segment data and reassemble it at the receiver’s end.
  • Tracks how much data has been sent and received.
  • Ensures data is reordered correctly if it arrives out of order.
  • Aids in detecting and retransmitting lost data.

Sequence Number Range and Data Limit

  • In the TCP header, the Sequence Number field is 32 bits long.
  • The range of possible values is from

0 to 2³² – 1 (i.e., 4,294,967,295).

  • This does not mean TCP is limited to 4 GB of data.
  • Sequence number wraparound allows TCP to continue data transmission beyond this limit during long connections.

Initial Sequence Number (ISN):

  • During connection setup, each device generates a random Initial Sequence Number (ISN).
  • ISNs are different for each direction of communication.
  • This helps avoid conflicts and ensures secure and unique identification of data bytes in a connection.
tcp
TCP

Wrap Around Concept in TCP

TCP uses a 32-bit sequence number field, which means the sequence numbers range from 0 to 2³² – 1. This gives a total of 4,294,967,296 (4 GB) unique sequence numbers.

Once all sequence numbers are used, and more data needs to be sent, the sequence numbers start again from 0. This reuse of sequence numbers is known as wrap around.

For example: If the starting sequence number is X, then TCP uses numbers from X to 2³² – 1, and then wraps around to 0 and continues up to X – 1.

Why Wrap Around Works

Even though sequence numbers are reused, it does not cause confusion because:

  • Every TCP packet has a lifetime (maximum time a packet can exist in the network), usually assumed to be 180 seconds.
  • As long as the wrap around time is greater than the lifetime of a packet, there's no conflict. The old packets would have expired by the time their sequence numbers are reused.

Wrap Around Time

Wrap Around Time is the time taken to use up all 2³² sequence numbers once. It depends on how fast the sequence numbers are consumed, which is determined by the bandwidth of the connection.

  • Higher bandwidthFaster consumptionShorter wrap around time
  • Lower bandwidthSlower consumptionLonger wrap around time

Wrap Around Time ∝ 1 / Bandwidth

How to Reduce Wrap Around Time

To reduce the time it takes to wrap around:

  • Increase bandwidth (more data sent per second)
  • Sequence number size is fixed (32-bit), so it cannot be reduced 

Examples

Example 1: Given n bits, how many sequence numbers are possible?

Explanation:

  • For 1 bit → 2 numbers are possible: 0, 1
  • For 2 bits → 4 numbers are possible: 00, 01, 10, 11
  • For 3 bits → 8 numbers are possible: 000, 001, 010, 011, 100, 101, 110, 111
  • For n bits → 2ⁿ numbers are possible, ranging from 0 to 2ⁿ - 1

Example 2: Given n sequence numbers, how many bits are required to represent them?

Explanation:

Let the number of bits required be x.

We know:

2ˣ = n

Taking logarithm base 2 on both sides:

x = log₂(n)

Example 3: Bandwidth = 1 GBps. How long can a packet stay on the link without repeating sequence numbers?

Explanation:

Bandwidth = 1 GBps = 10⁹ bytes/sec

Total sequence numbers = 2³² = 4,294,967,296

Wrap Around Time = Total Sequence Numbers / Bandwidth
= 2³² / 10⁹
= 4,294,967,296 / 1,000,000,000
= 4.294 seconds

Example 4: GATE-CS-2014-(Set-3) | Question 65 

Example 5: GATE CS 2018 | Question 32
 


Similar Reads