The Wayback Machine - https://web.archive.org/web/20240906170010/https://www.geeksforgeeks.org/calculation-of-tcp-checksum/
Open In App

Calculation of TCP Checksum

Last Updated : 19 Nov, 2021
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

In this article, we will learn a good concept of how the TCP/UDP checksum is calculated. 

When we receive data from the application it is broken into smaller data parts as the whole data from the application cannot be sent through the network to the receiver host. 

The protocol we use in OSI in the Transport layer is TCP. So, after breaking the data from the application layer into smaller parts. This broken part form the body of the TCP. 

The TCP header usually varies from 20 Bytes(with no bits of option fields being used) to 60 Bytes(with all bits of options field being used). 

It has fields like Source and Destination Port addresses, urgent pointer, Checksum, etc. 

In this article, we are only concerned about the CheckSum field of the TCP. 

The CheckSum of the TCP is calculated by taking into account the TCP Header, TCP body and Pseudo IP header. 

Now, the main ambiguity that arises that what is how can checksum be calculated on IP header as IP comes into the picture in the layer below the Transport Layer. 

In simple terms, it means that we are in Transport Layer and the IP data packet is created in Network Layer. 

Then how can we estimate the size of the IP header from the Transport because the guess/estimation would be definitely wrong and thus there would be no point in calculating the checksum on a field which is wrong at the beginning itself? 

The error checking capability of TCP/UDP in Transport Layer takes help from the network layer for proper error detection. 

But the important concept to note here is that we actually don’t use the IP header rather we use a part of the IP header. 

To overcome all these errors and increase error checking capability we use Pseudo IP header. 

Pseudo IP header: 
The pseudo-header is not an IP header rather it is a part of the IP header. We directly don’t use the IP header because in IP header there are many which would be continuously changing when then packets move along the network . Thus a part of the IP header is taken into account which don’t change as the IP packet moves in the network. 

The Fields of the Pseudo IP header are:- 
 

  1. IP of the Source 
     
  2. IP of the Destination 
     
  3. TCP/UDP segment Length 
     
  4. Protocol (stating the type of the protocol used) 
     
  5. Fixed of 8-bits 
     

So, the total size of the pseudo header(12 Bytes) = IP of the Source (32 bits) + IP of the Destination (32 bits) +TCP/UDP segment Length(16 bit) + Protocol(8 bits) + Fixed 8 bits 
 

An important concept should be noted that this Pseudo header is created in the Transport layer for calculation and after the calculation is done the Pseudo header is discarded. And the checksum is calculated by using the usual checksum method. 

So, this Pseudo Header is not transported across the network, rather the actual IP header which is formed in Network Layer is transported. 

So, the TCP checksum includes the:- 
 

1. Pseudo IP header 
2. TCP header
3. TCP body

 

After the calculation of the checksum using the above 3 fields, the checksum result is placed in the checksum field of the TCP header. 

As it is already stated that the Pseudo header is discarded and is not transported to the destination host then how does the Destination host check if the data is received correctly or not. Thus, the pseudo-header is once again created in the Transport layer of the Destination host and then again the checksum is calculated in the Transport Layer of Destination Host and finally, the checksum is calculated by the usual method of checksum and is confirmed if the data received is correct or not. 

Why IP header error checking two times is needed ? 

The IP header is checked two times the first time in the Transport layer and second time in Network Layer. The IP header is checked two times because double checking ensures that any error in the IP header can be detected with proper accuracy.
 



Similar Reads

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
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
Difference between Checksum and CRC
1. Checksum: Checksum is a widely used method for the detection of errors in data. This method is more reliable than other methods of detection of errors. This approach uses Checksum Generator on Sender side and Checksum Checker on Receiver side. 2. CRC: CRC or Cyclic Redundancy Check is the error detection method to detect the errors and is used b
1 min read
How Checksum Computed in UDP?
Answer: The UDP checksum is a 16-bit one's complement sum of the UDP header, payload, and a pseudo-header with IP addresses, protocol, and UDP length.Inclusion of ComponentsIt starts with the aggregation of the UDP header, payload, and a pseudo-header, which is a construct that includes the source and destination IP addresses, the protocol indicati
1 min read
Error Detection Code - Checksum
Checksum is the error detection method used by upper layer protocols and is considered to be more reliable than LRC, VRC and CRC. This method makes the use of Checksum Generator on Sender side and Checksum Checker on Receiver side. At the Sender side, the data is divided into equal subunits of n bit length by the checksum generator. This bit is gen
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
TCP Server-Client implementation in C
Prerequisites - Socket Programming in C/C++, TCP and UDP server using select, UDP Server-Client implementation in C If we are creating a connection between client and server using TCP then it has a few functionalities like, TCP is suited for applications that require high reliability, and transmission time is relatively less critical. It is used by
4 min read
TCP Connection Establishment
Prerequisite – TCP 3-Way Handshake Process TCP is a connection-oriented protocol and every connection-oriented protocol needs to establish a connection in order to reserve resources at both the communicating ends. Connection Establishment - 1. Sender starts the process with the following: Sequence number (Seq=521): contains the random initial seque
3 min read
TCP flags
In TCP connection, flags are used to indicate a particular state of connection or to provide some additional useful information like troubleshooting purposes or to handle a control of a particular connection. Most commonly used flags are "SYN", "ACK" and "FIN". Each flag corresponds to 1 bit information. Types of Flags: Synchronization (SYN) - It i
4 min read
What is TCP Window Scaling?
In the TCP header, the window size field is of size 16 bits. Using this field TCP users (client or server) can advertise a maximum of 216 = 65536 bytes or 64 KiB as its buffer size to its other end-user. But modern endpoint devices (e.g., phones, tabs, PCs, etc) have much more memory available in their buffers. This 16-bit field was enough during t
5 min read
Wrap Around Concept and TCP Sequence Number
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 T
6 min read
Devices used in each layer of TCP/IP model
Prerequisite - TCP/IP Model, Network Devices 1. Physical Layer - Physical layer of TCP/IP model is responsible for physical connectivity of two devices. Some of the devices used in Physical layers are, Hubs: Hubs are devices commonly used to connect segments of a LAN. It contains multiple input/output ports. when signal is at any input port, this s
4 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
OSI, TCP/IP and Hybrid Models
OSI Model is developed by International Organization for Standardization or ISO, the Open Systems Interconnection model or OSI model is a critical building block in networking. OSI Model helps in troubleshooting and understanding networks because of the layered approach that it follows. It consists of seven layers in which each layer has its functi
4 min read
Traditional TCP
Transmission Control Protocol (TCP) is the transport layer protocol that serves as an interface between client and server. The TCP/IP protocol is used to transfer the data packets between transport layer and network layer. Transport protocol is mainly designed for fixed end systems and fixed, wired networks. In simple terms, the traditional TCP is
4 min read
TCP/IP in Computer Networking
Introduction : TCP/IP (Transmission Control Protocol/Internet Protocol) is a suite of communication protocols that define the standards for transmitting data over computer networks, including the internet. The TCP/IP protocol is the foundation of the internet and enables devices to communicate with each other using a common language. The TCP/IP pro
8 min read
Various TCP and UDP ports
Transportation layer conventions utilize the idea of ports and multiplexing/demultiplexing to convey information to individual services listening on network nodes. These ports are spoken to by a solitary 16-bit number, implying that they can constitute a range of numbers 0-65535. This range has been separated by the IANA (Internet Assigned Numbers
4 min read
How to calculate Maximum Segment Size in TCP?
Maximum Segment Size refers to size of the largest segment that local host accepts within a single packet. It denotes largest amount of data that host can accept in single TCP segment. For establishing the TCP connection, both sender and receiver indicates Maximum Segment Size they can accept. While transmitting the packets over TCP connection send
3 min read
Vegas A ( Modified TCP-Vegas )
Vegas A is the modification of TCP Vegas. The A in Vegas A stands for adaptive.TCP Vegas has a fixed value of the constant alpha and beta. So it does not do better when it is in connection with TCP Reno. Therefore, in Vegas A these constants are not fixed but change according to the throughput and the extra data in the queue. In the starting, the v
4 min read
Construct a simple HTTP request on TCP protocol
HTTP Request : HTTP messages are how data is exchanged between a server and a client. In this, there are two types of messages where one is HTTP client request and the second is the response from the server.Messages in textual form and it is encoded in ASCII form, and span over multiple lines. And messages were openly sent across the connection in
3 min read
Similarities between TCP/IP model and OSI model
Pre-Requisite: Layers of OSI Model, TCP/IP Model OSI Model or Open Systems Interconnection is an architecture of 7 layers in which each layer has its work to perform whereas TCP/IP is a concise version of the OSI Model. TCP/IP Model consists of 4 layers rather than the 7 layers of the OSI Model. There are so many similarities between the TCP/IP mod
5 min read
Fast Recovery Technique For Loss Recovery in TCP
When the RTO timer expires but an ACK is not received, the sender confirms that the packet is lost due to congestion at intermediary devices. Now sender has to tackle this congestion state carefully. Fast Recovery is the packet loss recovery technique. Recovery means becoming inactive and not transmitting any new packet for some time. When there is
4 min read
Snooping TCP
In this article, we will discuss the overview of Snooping TCP, and its working, and then will discuss the advantages and disadvantages of Snooping TCP. Let's discuss it one by one. Overview :Snooping TCP is one of the classical TCP improvement approaches. This approach is designed to solve the end-to-end semantics loss in I-TCP. The basic concept i
3 min read
Selective Acknowledgments (SACK) in TCP
When a packet loss is detected in TCP communication between client and server, the next step is to recover the lost data packet. There are some of the algorithms for loss recovery in TCP. These are: Fast RecoverySelective Acknowledgments (SACK)Proportional Rate Reduction (PRR)Limitations of Fast Recovery:The ‘Fast Recovery’ mechanism in TCP Reno ha
5 min read
TCP vs UDP for Video Streaming
Prerequisite : TCP/IP Model, User Datagram Protocol (UDP)In this era of the modern internet with entertainment, education, gaming and all kinds of necessities streaming live everyday, the demand of an uninterrupted video stream is highly adamant. To dive into the topic of which protocol is better for video streaming, one must be familiar with the T
6 min read
Examples of TCP and UDP in Real Life
Today we will see the Real-Life Examples of TCP and UDP in Computer Networks Before looking at the Real-Life Examples of TCP and UDP, Let's see What is Computer Network? A Computer Network is a set of devices (Nodes) that are connected to each other by communication links to share digital information.The communication links can either be wireless m
8 min read
Why is YouTube using TCP but not UDP?
Overview :In this article, we will discuss about which technology YouTube uses for streaming videos and music on its platform. YouTube is an American online video sharing and web-based media stage by Google. It is most utilized sites in the entire world. YouTube is a free video-facilitating site that permits individuals to store and serve video con
3 min read
Why does Netflix use TCP but not UDP for streaming video?
Overview :In this article, we will discuss which technology Netflix uses for streaming online movies and web series on its platform. Netflix is an American subscription-based streaming service provider company. It is famous for streaming online videos, web series, and movies based on its subscription that its customers buy. There are two types of t
3 min read
When Transmission Control Protocol (TCP) most appropriate?
TCP(Transmission Control Protocol) is a protocol of the Transport layer. TCP is a connection-oriented, reliable, and secured protocol. To provide reliable service TCP implements Error control, Congestion control, Flow control. Services provide by TCP : The process to process communication -It is achieved using the port number.Stream Delivery Servic
2 min read