Once TCP establishes a session, it is then able to keep track of the conversation within that session. Because of the ability of TCP to track actual conversations, it is considered a stateful protocol. A stateful protocol is a protocol that keeps track of the state of the communication session. For example, when data is transmitted using TCP, the sender expects the destination to acknowledge that it has received the data. TCP tracks which information it has sent and which information has been acknowledged. If the data is not acknowledged, the sender assumes the data did not arrive and resends it. The stateful session begins with the session establishment and ends when the session is closed with session termination.
Note: Maintaining this state information requires resources that are not necessary for a stateless protocol, such as UDP.
TCP incurs additional overhead to gain these functions. As shown in the figure, each TCP segment has 20 bytes of overhead in the header encapsulating the application layer data. This is considerably more than a UDP segment, which only has 8 bytes of overhead. Extra overhead includes:
- Sequence number (32 bits) - Used for data reassembly purposes.
- Acknowledgement number (32 bits) - Indicates the data that has been received.
- 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, that indicate the purpose and function of the TCP segment.
- Window size (16 bits) - Indicates the number of segments that can be accepted at one time.
- Checksum (16 bits) - Used for error checking of the segment header and data.
- Urgent (16 bits) - Indicates if data is urgent.
Examples of applications that use TCP are web browsers, email, and file transfers.