In Transport Layer two Protocols are mostly used; one is UDP and the other one is TCP depending on the type of data that will pass across the network.
UDP stands for User Datagram Protocol. It is a communications protocol that facilitates the exchange of messages between computing devices in a network.
UDP is a communication protocol used across the Internet for especially time sensitive transmissions such as video or audio playback or DNS lookups. It is faster way of communication but less reliable as lost data are not retransmitted across the network.
TCP stands for Transmission Control Protocol.
TCP is used in the Transport Layer after the data comes from the Application Layer through Presentation and Session Layer.
The 24 Bytes Headers is added to the data and that Header is known as TCP Header.
Today we are going to learn TCP Header but before that let us understand the functions of TCP Transmission Control Protocol.
Byte Streaming is the process for converting bites into Bytes. Bits come from the Application Layer in continuous process and TCP collects those bits and converts those into Bytes and further those Bytes are grouped into Segment. This process is known as Segmentation which is the most important function of TCP. Therefore Segment is a collection of Bytes.
TCP is Connection Oriented service and it uses 3-Way Hand Shaking.
TCP is a connection-oriented protocol, which means a connection is established and maintained until the application programs at each end have finished exchanging messages.
The 3-Way Hand Shaking process involves the following:-
In this way the 3-Way Hand Shaking process ensure the reliability of the data that the full data will be received at the receiver end.
TCP support full duplex communication because both the sender and receiver end can send data at same time; once the connection is established.
Piggybacking is another important process of the TCP. After receiving the packets sender receives acknowledgement of the data from the receiver. Instead of sending acknowledgement of each and every packet the receiver end can send single acknowledgement for a group of received packets. The receiver waits until its network layer passes in the next data packet. The delayed acknowledgment is then attached to this outgoing data frame to reduce the network load.
Another important function of TCP is Error Control. TCP provides reliability using error control. Error control includes mechanisms for detecting lost segments, out-of-order segments, corrupted segments and duplicated segments. Error control also includes a mechanism for correcting errors after they are detected. So that the damaged packets can be identified and the same can be retransmitted across the network to the destination end.
Flow Control is another important function performs by TCP. It basically means that TCP will ensure the limitations of the receiver end so that a sender is not overwhelming a receiver by sending packets faster than it can consume.
TCP not only take care of the receiver end's capacity but in order to controls the Congestion in the network TCP also take care of the network through which the data packet will be passed.
Therefore the major Application Layer's Protocols are rely on TCP such as World Wide Web, E-Mail, Remote Administration, FTP, SSL and many more where data reliability is most significant. So data packets losses during transmit are taken care by receiving acknowledgement of received data from the receiver end but unlike UDP connection; TCP does not support real time communication like live audio and video steaming.
Now let us discuss about the TCP Header;
Both UDP and TCP use headers as part of packaging the message data for transfer over network connections. TCP Header can be minimum of 20 bytes and maximum of 60 bytes with an option for additional data, while UDP headers are limited to 8 bytes in size.
TCP wraps each data packet with a Header containing 10 mandatory fields inclusive of total 20 or more bytes. Each header holds information about the connection and the current data that is being sent.
Let us start discussing about the Header Fields;
Source and Destination 16 bits port number is the first two parallel fields in the header. The source port number identifies the application process that sent the data and the destination port number identifies the application process that is to receive the data.
The 32 bit Sequence number field defines the number assigned to the first byte of data contained in this segment. The Sequence number is a counter that keeps track of every byte sent across the network by a host.
The 32 bit Acknowledgement number is the next expected byte number. This number is a counter to keep track of every byte that has been received. So the acknowledgment number field holds the sequence number of the next byte the receiver is expecting on this connection.
Header Length determines the length of TCP/IP header in 4 bits. It is to be calculated at the scale of four. So; that value of header is multiplied by 4. The minimum header length value can be (0101) that is 5 in decimal and then multiply 5 with 4 because it is calculated as scale of four (5 x 4) = 20 bytes; which is the minimum size of a TCP header. The maximum header length can be (1111) that is 15 in decimal and then multiply 15 with 4 (15 x 4) = 60 bytes; which is the maximum size of a TCP header.
Reserved six bits for Flags; six flags are there in the TCP header.
Urgent Flag (URG) if this flag is set to one then this packet contains some urgent data or if the (URG) is set to zero then this packet contains regular data.
Acknowledgement Flag (ACK) if this flag is set to one then this packet carries acknowledgement notification and the acknowledgement 32 bits number is mentioned above.
Push Flag (PSH) if this flag is set to one then it inform the receiver end to forward the data to the application layer without waiting for buffer memory.
Reset Flag (RST) this flag reset the TCP connection if it is set to one.
Synchronization Flag (SYN) for establishing the connection this flag is set to one. If this flag is set to one then it is the first data bit which the sender wants to send the receiver after establishing connection.
Finished Flag (FIN) if this flag is set to one then this contains the last bit of data during this period of connection and this session is needed to be terminated now.
Window Size is 16 bits important tool to manage the flow control. It advertises the window size in the header of the packet; which informs about the maximum capacity of accepting data bits.
Checksum is 16 bits field used in order to provide basic protection against transmission errors; TCP/IP uses checksums in its headers. The receiving side calculates the checksum on the data; weather the same data are received comparing with sender using the same algorithm as the sender that is received and compares its value to the checksum passed in the header. Therefore it is the part of error control process of TCP.
Urgent Pointer is 16 bits field which holds the range of urgent data in case the (URG) flag is set to one. It indicates that how much data in the current segment counting from the first byte is urgent. So it defines the number which must be added to the sequence number to get the number of the last urgent bytes in the current segment.
Option & Padding last field in TCP header.
The TCP segment has an options field that consists of 0 or more 32-bit words and provides a way to deal with limitations of the original header. The MSS (Maximum Segment Size) is defined as the largest block of data that a sender using TCP will send to the receiver. Padding is basically used to make sure that the IP packet header has a length that is a multiple of 32 bits. It is needed because of the varying length of the options field in the IP header.
Window Size in TCP What is TCP Header Format Urgent Pointer in TCP Header URG Flag in TCP Header TCP Header Size TCP Header Format Explanation SYN in TCP Header SYN Flag in TCP Header Source Port in TCP Header Sequence Number in TCP Header RST in TCP Header Reserved Bits in TCP Header PSH Flag in TCP Header Options and Padding in TCP Header Header Length in TCP FIN Flag in TCP Header Checksum TCP Header Acknowledgement Number in TCP ACK in TCP Header Window Size in TCP What is TCP Header Format Urgent Pointer in TCP Header URG Flag in TCP Header TCP Header Size TCP Header Format Explanation SYN in TCP Header SYN Flag in TCP Header Source Port in TCP Header Sequence Number in TCP Header RST in TCP Header Reserved Bits in TCP Header PSH Flag in TCP Header Options and Padding in TCP Header Header Length in TCP FIN Flag in TCP Header Checksum TCP Header Acknowledgement Number in TCP ACK in TCP Header Window Size in TCP What is TCP Header Format Urgent Pointer in TCP Header URG Flag in TCP Header TCP Header Size TCP Header Format Explanation SYN in TCP Header SYN Flag in TCP Header Source Port in TCP Header Sequence Number in TCP Header RST in TCP Header Reserved Bits in TCP Header PSH Flag in TCP Header Options and Padding in TCP Header Header Length in TCP FIN Flag in TCP Header Checksum TCP Header Acknowledgement Number in TCP ACK in TCP Header