Useful Articles

25/recent/ticker-posts

TCP Header Details

TCP Header Details

TCP (Transmission Control Protocol) is a protocol used at Transport layer for providing reliable connectivity to various other protocols for example FTP, Telnet, BGP etc. It establishes a connection also know as TCP 3-Way Handshake before sending any data and everything that it sends is acknowledged by the receiver. In this lesson we will go through the TCP Header Details and its different fields.

Among the services TCP provides are stream data transfer, reliability, efficient flow control, full-duplex operation, and multiplexing. With stream data transfer, TCP delivers an  stream of bytes identified by sequence numbers. This service benefits applications because they do not have to chop data into blocks before handing it off to TCP. Instead, TCP groups bytes into segments and passes them to IP for delivery.

TCP offers reliability by providing connection-oriented, end-to-end reliable packet delivery through an inter network. It does this by sequencing bytes with a forwarding acknowledgment number that indicates to the destination the next byte the source expects to receive. Bytes not acknowledged within a specified time period are re-transmitted.

The reliability mechanism of TCP allows devices to deal with lost, delayed, duplicate, or misread packets. A time-out mechanism allows devices to detect lost packets and request re-transmission.

TCP offers efficient flow control, which means that, when sending acknowledgments back to the source, the receiving TCP process indicates the highest sequence number it can receive without overflowing its internal buffers.

TCP header is 20 bytes long. Below is the TCP header format and the various fields of  the TCP Header.
 
TCP Header Details, TCP Header


Below is  the description of all the fields of the TCP Header.
  • Source port - It is a 16-bit field that specifies the application port number of the host sending the data.
  • Destination port - It is a 16-bit field that specifies the port number of the application requested on the destination host.
  • Sequence number - It is a 32-bit field that is used to put the data back in the correct order and also used to re-transmit missing or damaged data segments.
  • Acknowledgment number - It is a 32-bit field that is used by the receiving host to acknowledge the successful delivery of segments based on which the next stream of data segments is sent by the source. This field also updates the source in which the sequence number data segment has to be sent next and similarly used by the receiver to expect the next sequence of data segments.
  • Header Length(HLEN) - It is a 4-bit field that defines the number of 32-bit words in the header. This field also indicates the length of the TCP header so that we know where the actual data begins.
  • Reserved - It is a 3 bits field with value always set to 0.
  • Code Bits(Flags) - There are 9 bits in this filed with each have a specific purpose. An example of the use of bits in this field is during TCP 3 Way Handshake (SYN, ACK) used establishing a connection between source and destination hosts before sending the data. Some of the fields are used while sending data and while the connection is terminated with the destination host. Each bit of the code bits is 1 bit long. Below are the details:
  1. URG(1bit): indicates that the Urgent pointer field is significant. When this bit is set, the data should be treated as a priority over other data.
  2. ACK(1bit): used for the acknowledgment of successful delivery of the previous segment.
  3. PSH(1bit): Push function. Updates the receiving host to push the buffered data to the receiving application.
  4. RST(1bit): Used to reset the connection, when the TCP host receives the segment with RST bit set the connection is reset immediately. This bit is used when there are unrecoverable errors and it’s not a normal way to finish the TCP connection.
  5. SYN(1bit): As discussed earlier, this bit is used during TCP 3 Way handshake process.
  6. FIN(1bit): This bit is used to finish end the TCP connection in a normal way by both sending and receiving hosts. This bit also specifies end of data.
  7. NS (1 bit), CWR (1 bit), ECE (1 bit) are used for Explicit Congestion notification along with IP header (TOS) field
  • Window - It is a 16-bit field that is used to negotiate the window size b/w sending and receiving hosts. This file specifies the number of bytes the receiver is willing to receive. It is used so the receiver can tell the sender that it would like to receive more data than what it is currently receiving. Window size is negotiated based on sender and receiver buffers and is negotiated to the lowest value.
  • Checksum - It is a 16 bits field that is used for integrity checks TCP segment. It is like CRC because TCP doesn’t trust the lower layers and checks everything. The Cyclic Redundancy Check (CRC) checks the header and data fields.
  • Urgent Pointer -  It is a 16 bits field that indicates the end of urgent data. This field is used when the URG bit is set in Code bits(flags).
  • Options - Sets the maximum TCP segment size to either 0 or 32 bits, if any.
  
Below is the Wireshark Capture of the TCP Header. This TCP Header encapsulates the BGP Packet.

TCP Header Details, TCP Header, TCP Header Wireshark Capture
 
 
The TCP Packet (i.e TCP header + Segment) is sent to the Network Layer where it get encapsulated completely under an IP Header
 
 
 
I hope you have found this article informative and useful and now have a fair understanding of the TCP Header and its important fields such as  Source Port, Destination Port, Sequence Number, Acknowledgement Number, Flags, Window, and Urgent Pointer. For any of the related queries or feedback, kindly write to us at networkurge@gmail.com