The Transmission Control Protocol (TCP) is one of the central protocols of the Internet Protocol Suite. TCP is one of the two original components of the entire Internet Protocol Suite, commonly referred to as TCP/IP. IP manages the lower-level transmissions from machine to machine and TCP functions at a higher level, concerned only with the two end computers.

TCP (Transmission Control Protocol) is the major transport protocol utilized in IP networks. The TCP protocol exists on the Transport Layer of the OSI Model. The TCP protocol is a connection-oriented protocol which provides end-to-end reliability.

By connection-oriented, we mean that before two network nodes can communicate using TCP, they must first complete a handshaking protocol to create a connection. When we say that TCP provides end-to-end reliability, we mean that TCP includes mechanisms for error detection and error correction between the source and the destination.

These properties of TCP are in contrast to UDP, which is connectionless and unreliable.Higher layer protocols which utilize TCP include HTTP, SMTP, NNTP, FTP, telnet, SSH, and LDAP.

Diagram of the TCP Header

 TCP Header Format
 -----------------

 0 1 2 3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Source Port | Destination Port |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Acknowledgment Number |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data | |U|A|P|R|S|F| |
| Offset| Reserved |R|C|S|S|Y|I| Window |
| | |G|K|H|T|N|N| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum | Urgent Pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

  • Source Port: It is 16 bit long and is used to identify the sending port.
  • Destination Port: It is 16 bit long and is used to identify the receiving port.
  • Sequence Number: It is 32 bit long. If the SYN flag is set then this becomes the first sequence number. The real sequence number of the first data byte will be this sequence number plus 1. If the SYN flag is not set, then this becomes the sequence number of the first date byte.
  • Acknowledgement Number: It is 32 bit long. If the ACK flag is set then this field’s value is the next sequence number that the receiver is expecting.
  • Data Offset: It is 4 bit long. It indicates the size of the TCP header in 32-bit words. The least size header is 5 words and the maximum is 15 words. As the name suggest, it is also the offset from the start of the TCP segment to the real data.
  • Reserved: It is 4 bit long. It is basically reserved for future use and must be set to zero.
  • Flags: They are also known as Control Bits. They shelter 8 1-bit flags for various purposes.
    CWR – It stands for Congestion Window Reduced (CWR) flag. It is set by the sending machine to specify that it received a TCP segment with the ECE flag set.
    ECE – It stands for Explicit Congestion Notification. It specifies that the TCP peer is ECN capable during 3-way handshake.
    URG – It specifies that the URGent pointer field is important.
    ACK – It specifies that the ACKnowledgment field is important.
    PSH _ It is used for Push function.
    RST – It is used to ReSeT the connection.
    SYN – It is used to SYNchronize the sequence numbers.
    FIN – It indicates a FINish mark specifying that sender do not have any more data to transfer.
  • Window – It is 16 bit long. It is basically the size of the receiving window, which indicates the number of bytes that the receiver can presently accept.
  • Checksum – It is 16 bit long. It is used for error diagnoses of the header and data.
  • Urgent pointer – It is 16 bit long. if the URG flag is set, then this field is an offset from the sequence number specifying the last urgent data byte.
  • Options – It is a variable length field. The complete length of this field must be a multiple of a 32-bit word and the data offset field adjusted appropriately.
  • Data – It is a variable length field. This portion holds the actual data of the TCP segment.

Additional Reading on TCP

The TCP protocol is defined in RFC 793: Transmission Control Protocol.