TCP Segment Format with Diagram

TCP Segment Format with Diagram is shown in the figure below :

TCP Segment Format

The TCP segment consists of header fields and a data field. The data field contains a chunk of application data. The MSS (Maximum Segment Size) limits the maximum size of a segment’s data field.

When TCP sends a large file, such  as an image as part of a web page, it typically breaks the file into chunks of size MSS (except for the last chunk, which will often be less than the MSS).

Interactive applications, however, often transmit data chunks that are smaller than the MSS; for example, with remote login applications like Telnet, the data field in the TCP segment is often only one byte. Because the TCP header is typically 20 bytes (12 bytes more than the UDP header), segments sent by Telnet may be only 21 bytes in length.

The figure above shows the structure of the TCP segment. As with UDP, the header includes source and destination port numbers, which are used for multiplexing/demultiplexing data from/to upper-layer applications.

Also, as with UDP, the header includes a checksum field. A TCP segment header also contains the following fields:

  • The 32-bit sequence number field and the 32-bit acknowledgement number field are used by the TCP sender and receiver in implementing a reliable data transfer service, as discussed below.
  • The 16-bit receive window field is used for flow control. It is used to indicate the number of bytes that a receiver is willing to accept.
  • The 4-bit header length field specifies the length of the TCP header in 32-bit words. The TCP header can be of variable length due to the TCP options field. (Typically, the options field is empty, so that the length of the typical TCP header is 20 bytes).
  • The optional and variable-length options field is used when a sender and receiver negotiate the maximum segment size (MSS) or as a window scaling factor for use in high-speed networks. A time-stamping option is also defined. See RFC 854 and RFC 1323 for additional details.
  • The flag field contains 6 bits. The ACK bit is used to indicate that the value carried in the acknowledgement for a segment that has been successfully received. The RST, SYN, and FIN bits are used for connection setup and teardown. Setting the PSH bit indicates that the receiver should pass the data to the upper layer immediately. Finally, the URG bit is used to indicate that there is data in this segment that the sending-side upper-layer entity has marked as “urgent”. The location of the last byte of this urgent data is indicated by the 16-bit urgent data pointer field. TCP must inform the receiving-side upper-layer entity when urgent data exists and pass it to a pointer to the end of the urgent data. (In practice, the PSH, URG, and the urgent data pointer are not used. However, we mention these fields for completeness).