Open In App

Wrap Around Concept and TCP Sequence Number

Last Updated : 31 May, 2023
Like Article

Prerequisite – TCP | Services and Segment structure 
Transmission Control Protocol (TCP) is one of the most important protocols of the internet protocol. It provides full transport-layer service to applications and generates a virtual circuit between sender and receiver that is active for the duration of the transmission. Its segment consists of a TCP header, TCP options, and the data that the segment transports. 

Sequence Numbers – 
The 32-bit sequence number field defines the number assigned to the first byte of data contained in this segment. TCP is a stream transport protocol. To ensure connectivity, each byte to be transmitted is numbered. During connection establishment, each party uses a Random number generator to create an initial sequence number (ISN), which is usually different in each direction. We know that a TCP sequence number is 32 bit. So it has finite (from 0 to (232-1) = 4 Giga sequence numbers) and it means we will be able to send only 4GB of data with a unique sequence number not more than that. It helps with the allocation of a sequence number that does not conflict with other data bytes transmitted over a TCP connection. An ISN is unique to each connection and separated by each device. 

Wrap Around Concept – 
It can happen at a high rate of traffic, all the sequence numbers got used up. The sequence number for every packet has to be unique, but since it is finite (4 Giga) at some point in time the Sequence number is completely consumed up. The sequence numbers which were used, when available can be used again as per requirement and this reusing of sequence numbers is known as Wraparound concept

In simple words “Using the sequence numbers again and again once all of them got used up, in order to maintain the continuity of data transfer ” is called Wrap around the concept. This helps to send more and more data without worrying about how much data is to be sent. As the sequence numbers can be used again and again, so there is no limit on the quantity of data. 

When and how wrap around is implemented? 
For example, if I am downloading software of size 4GB+ 2 bytes, but the sequence number available is only 4GB the rest two-byte won’t get any sequence number. In this kind of cases, the sequence numbers are wrapped, i.e., they are used again and again as per the requirement. This wrapping is affected by the random initial sequence number. We may get a lesser number of the sequence number in the beginning but after all sequence number is consumed again the sequence number will start from 0. 

From wherever we start using sequence numbers we will get 232 sequence numbers. Hence we can say that reusing a sequence number as per the requirement is the wrap concept of the TCP sequence number. Now if we have a wrap concept then a new concept comes, i.e., Wrap Around Time which depends on wrap-around sequence numbers. 

Wrap Around Time – 
Time taken to wrap around is called wrap-around time. It means if we start from sequence number 0 (or it may be anything), after how much time we are going to again use this same sequence number. Wrap around time is the time taken to start reusing the same sequence number also it can be said that the time taken to repeat the sequence number is as per the requirement. Wrap-around time depends on the sequence numbers and bandwidth. As the bandwidth is the rate of bits at which bits (sequence number) are consumed. The faster is the consumption rate, the faster is the consumption of sequence numbers. 


Wrap Around Time
= (Total sequence number) / (Bandwidth)
= (232) / (Bandwidth) 

Why is Wrap Around possible? 
There is a concept termed as Life Time, in the worst case a packet will require 3 minutes (180sec) to reach the destination (i.e., the lifetime of the packet). In today’s technology, the same sequence number will be available after 180 sec but we are not going to use it before wrap-around time. As long as Wrap Around Time > Life Time of a packet there will be no problem in using the same sequence number. After wrap-around the time the lifetime of the segments finishes, which means in that very time, a timeout occurs. After all sequence numbers are used and their lifetime finishes there is no harm in using the same sequence number again. 

Reducing Wrap Around Time – 
If the total number of bits to be consumed is equal to the sequence number then there will be no need to wrap around the sequence number. But this is not possible and we are going to use wrap-around concept. Since wrap-around time is directly dependent on a number of the Sequence numbers and inversely dependent on Bandwidth (Rate at which data will flow). 

More the Sequence numbers available, higher will be wrap-around time. Lesser the bandwidth, the higher the wrap-around time. So in order to reduce the wrap-around time, we need to: 

  1. Reduce the sequence numbers or 
  2. Increase the bandwidth (possible) 

Example-1: Given n bits how many sequence numbers are possible? 
Explanation – 
For 1 bit, 2 numbers are possible, i.e., 0 and 1 
For 2 bits, 4 numbers are possible, i.e., 00, 01, 10, 11 
for 3 bits 8 numbers are possible, i.e., 000, 001, 010, 011, 100, 101, 110, 111 .. and so on 
for n bits 2^n numbers are possible i.e., from 0 to 2n-1 (in binary). 

Example-2: Given n number of sequence numbers how many bits are required to represent the set? 
Explanation – 
Let us need x number of bits, we know that 2x = n 

=> x log(2) = log(n) 

We will have, 

=> x = log(n) 

Taking base 2 of given logs. 

Example-3: Bandwidth of channel is given as 1 GBps. How long can a packet stay in the link without worrying about the problem of having 2 packets with the same sequence numbers? 
Explanation – 

Bandwidth = 1 GBps = 109 
Sequence numbers = 232

So, Wrap around time: 
= Sequence number/Bandwidth
=232 / 109
=4.294 seconds 

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

Example-5: GATE CS 2018 | Question 32

Similar Reads

TCP Tahoe and TCP Reno
TCP is known as a connection-oriented protocol, which ensures reliability and is also responsible for congestion control mechanisms in the network. TCP Tahoe and TCP Reno are two techniques of TCP congestion control, these are used when the sender receives three duplicate acknowledgments. TCP Tahoe where Tahoe is a lake in the USA. This particular
4 min read
TCP Fast Open and TCP/IP Acceleration
The TCP Fast Open (TFO) and TCP/IP Acceleration are techniques used to improve the performance and efficiency of TCP connections in computer networks. These techniques aim to reduce the latency and improve the throughput of the TCP connections, especially for short-lived connections and web browsing scenarios. TCP Fast Open (TFO): The TCP Fast Open
3 min read
TCP with explicit link failure notification (TCP-ELFN)
TCP with Explicit Link Failure Notification (TCP-ELFN) is an end to end approach used in TCP Ad Hoc wireless networks to improve the performance by decoupling the path break information from congestion information. TCP-ELFN does not depend upon any routing protocols as it requires explicitly only the link failure notification when there is a path f
2 min read
Basic concept of TCP-Vegas
TCP Reno and TCP Tahoe models can determine the congestion in the network only when there some packet loss occurred in the system. So in these models, we have compensated for the packet to sense the congestion in the network. In these models when packet loss occurs the window size is decreased and the system enters the congestion avoidance phase. W
3 min read
How TCP Sequence Number Works?
Answer: TCP sequence numbers are 32-bit numbers used to uniquely identify each byte of data in a TCP connection, starting with an initial sequence number (ISN) and incremented for each byte sent.Working of TCP Sequence Number1. Numbering the sequence: Just like the parts of your letter, each data segment sent over TCP is numbered. This ensures all
1 min read
Difference between Turn Around Time (TAT) and Waiting Time (WT) in CPU Scheduling
In CPU Scheduling, we often need to find the average Turnaround and Waiting Time with the help of Arrival, Burst and Completion Time. Let's have a brief look of them: Turnaround Time (TAT): It is the time interval from the time of submission of a process to the time of the completion of the process.The difference b/w Completion Time and Arrival Tim
2 min read
Minimum and Maximum Length of the Header in the TCP Segment and the IP Datagram
The minimum and maximum length of the header in the TCP segment is 20 Bytes and 60 bytes respectively. The minimum and maximum length of the header in the IP datagram are 20 Bytes and 60 Bytes respectively. What is a TCP Header?The below diagram represents the TCP header. Necessary fields for TCP header 4B Source Port Destination Port 4B Sequence N
4 min read
Differences between TCP and UDP
Prerequisite - Transport Layer responsibilities Transmission Control Protocol (TCP) and User Datagram Protocol (UDP) both are protocols of the Transport Layer. TCP is a connection-oriented protocol where as UDP is a part of the Internet Protocol suite, referred to as the UDP/IP suite. Unlike TCP, it is an unreliable and connectionless protocol. Tra
7 min read
Difference Between OSI Model and TCP/IP Model
Data communication is a process or act in which we can send or receive data. For data communication two models are available. We will discuss these two models in this article and also see the differences between these two articles. OSI ModelTCP/IP ModelOSI ModelOSI stands for Open Systems Interconnection. It has 7 layers Physical layer, Data Link l
3 min read
TCP and UDP in Transport Layer
Layer 3 or the Network layer uses IP or Internet Protocol which being a connection less protocol treats every packet individually and separately leading to lack of reliability during a transmission. For example, when data is sent from one host to another, each packet may take a different path even if it belongs to the same session. This means the p
4 min read