TCP is a stateful protocol. A stateful protocol is a protocol that keeps track of the state of the communication session. To track the state of a session, TCP records which information it has sent and which information has been acknowledged. The stateful session begins with the session establishment and ends when closed with the session termination.
The Transmission Control Protocol (TCP) header is the first 24 bytes of a TCP segment that contains the parameters and state of an end-to-end TCP socket. The TCP header is used to track the state of communication between two TCP endpoints. An example of a TCP header is shown below.
As shown in the figure, each TCP segment has 20 bytes of overhead in the header encapsulating the application layer data:
Source Port (16 bits) and Destination Port (16 bits) – Used to identify the application.
Sequence number (32 bits) – Used for data reassembly purposes.
Acknowledgment number (32 bits) – Indicates data has been received and the next byte expected from the source.
Header length (4 bits) – Known as ʺdata offsetʺ. Indicates the length of the TCP segment header.
Reserved (6 bits) – This field is reserved for the future.
Control bits (6 bits) – Includes bit codes, or flags, which indicate the purpose and function of the TCP segment.
Window size (16 bits) – Indicates the number of bytes that can be accepted at one time.
Checksum (16 bits) – Used for error checking of the segment header and data.