TCP Header Details

TCP header is 20 bytes long. Below is the TCP header format and details of 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.