When you connect to the Internet, you establish a con­nec­tion between a router and a computer or mobile device in a few simple steps, whether you’re using wired or wireless tech­nol­o­gy. Nothing else is required because the system au­to­mat­i­cal­ly logs in to the network and obtains the unique Internet address that you need to receive and send data. This is made possible by a set of protocols known as the Internet protocol suite. One of the oldest and most important protocols in the suite is the Trans­mis­sion Control Protocol (TCP). It de­ter­mines how network devices exchange data.

What is TCP (Trans­mis­sion Control Protocol)?

The Trans­mis­sion Control Protocol, or TCP protocol for short, is a standard for ex­chang­ing data between different devices in a computer network. This protocol dates back to 1973, when computer sci­en­tists Robert E. Kahn and Vinton G. Cerf published the first version of the standard as part of a research paper. However, it took another eight years before TCP was stan­dard­ized in RFC 793. Since then, there have been a number of im­prove­ments and ex­ten­sions, although the core of the protocol has remained unchanged. The current version, which is defined in RFC 7323 is from 2014.

The current version of the TCP protocol allows two endpoints in a shared computer network to establish a con­nec­tion that enables a two-way trans­mis­sion of data. Any data loss is detected and au­to­mat­i­cal­ly corrected, which is why TCP is also called a reliable protocol. Together with UDP and SCTP, TCP forms the group of trans­mis­sion protocols belonging to the Internet protocol suite that are located at the transport layer in the network ar­chi­tec­ture according to the OSI model. The term TCIP/IP protocol stack is also commonly used to refer to the Internet protocol suite since the TCP protocol is almost always based on the Internet protocol (IP) and this con­nec­tion is the foun­da­tion for the majority of public and local networks and network services.

How exactly do TCP con­nec­tions work?

TCP allows for trans­mis­sion of in­for­ma­tion in both di­rec­tions. This means that computer systems that com­mu­ni­cate over TCP can send and receive data at the same time, similar to a telephone con­ver­sa­tion. The protocol uses segments (packets) as the basic units of data trans­mis­sion. In addition to the payload, segments can also contain control in­for­ma­tion and are limited to 1,500 bytes. The TCP software in the network protocol stack of the operating system is re­spon­si­ble for es­tab­lish­ing and ter­mi­nat­ing the end-to-end con­nec­tions as well as trans­fer­ring data.

The TCP software is con­trolled by the various network ap­pli­ca­tions, such as web browsers or servers, via specific in­ter­faces. Each con­nec­tion must always be iden­ti­fied by two clearly defined endpoints (client and server). It doesn’t matter which side assumes the client role and which assumes the server role. All that matters is that the TCP software is provided with a unique, ordered pair con­sist­ing of IP address and port (also referred to as "2-tuple" or "socket") for each endpoint.

The three-way handshake: How a TCP con­nec­tion is es­tab­lished in detail

Pre­req­ui­sites for es­tab­lish­ing a valid TCP con­nec­tion: Both endpoints must already have a unique IP address (IPv4 or IPv6) and have assigned and enabled the desired port for data transfer. The IP address serves as an iden­ti­fi­er, whereas the port allows the operating system to assign con­nec­tions to the specific client and server ap­pli­ca­tions.

Tip

For a detailed ex­pla­na­tion of how TCP and IP interact, see our in-depth article on TCP/IP.

The actual process for es­tab­lish­ing a con­nec­tion with the TCP protocol is as follows:

  1. First, the re­quest­ing client sends the server a SYN packet or segment (SYN stands for syn­chro­nize) with a unique, random number. This number ensures full trans­mis­sion in the correct order (without du­pli­cates).
  2. If the server has received the segment, it agrees to the con­nec­tion by returning a SYN-ACK packet (ACK stands for ac­knowl­edg­ment) including the client's sequence number plus 1. It also transmits its own sequence number to the client.
  3. Finally, the client ac­knowl­edges the receipt of the SYN-ACK segment by sending its own ACK packet, which in this case contains the server's sequence number plus 1. At the same time, the client can already begin trans­fer­ring data to the server.

Since the TCP con­nec­tion is es­tab­lished in three steps, the con­nec­tion process is called a three-way handshake.

Note

If the server port is closed or access is blocked, the client receives a TCP RST packet (reset) instead of an ac­knowl­edg­ment packet.

TCP teardown: How a con­trolled TCP con­nec­tion ter­mi­na­tion works

Both sides of a con­nec­tion can terminate a TCP con­nec­tion, and even one-sided ter­mi­na­tion is also possible. This is also known as a half-open con­nec­tion, whereby the other side is still allowed to transfer data even if one side has already dis­con­nect­ed.

The in­di­vid­ual steps of two-way ter­mi­na­tion (initiated by the client for the sake of sim­plic­i­ty in this example) can be sum­ma­rized as follows:

  1. The client sends a FIN segment to notify the server that it no longer wants to send data. It sends its own sequence number, just as it does when the con­nec­tion is es­tab­lished.
  2. The server ac­knowl­edges receipt of the package with an ACK segment that contains the sequence number plus 1.
  3. When the server has finished the data transfer, it also sends a FIN packet, to which it adds its sequence number.
  4. Now it is the client's turn to send an ACK packet including the sequence number plus 1, which of­fi­cial­ly ter­mi­nates the TCP con­nec­tion for the server.

However, the con­nec­tion is not im­me­di­ate­ly ter­mi­nat­ed for the side that sent the last ACK segment (in our case, the client). Since there’s no guarantee that the last packet sent has actually arrived, the client or server will initially remain in time-wait state until the maximum lifetimes of the ACK segment and any new FIN segments (according to RFC 793, two minutes for each segment) have expired.

What is the structure of the TCP header?

Typically, the header of a TCP packet contains the data required for con­nec­tion and data trans­mis­sion with the Trans­mis­sion Control Protocol. This header data (which contains control in­for­ma­tion) precedes the payload to be trans­ferred and is typically 20 bytes (160 bits) in size. It is followed by up to 40 bytes (320 bits) of ad­di­tion­al in­for­ma­tion, which is optional and not used in all packets.

Note

TCP segments without payload data, es­sen­tial­ly pure headers, are also allowed if only ac­knowl­edg­ments, error messages, etc. need to be trans­mit­ted, as in the case of SYN and FIN messages (con­nec­tion es­tab­lish­ment/ter­mi­na­tion).

The detailed structure of the TCP header is as follows:

The in­di­vid­ual com­po­nents or fields of the header of the TCP protocol have the following meaning:

Source port (16 bits): Iden­ti­fies the port number of the sender.

Des­ti­na­tion port (16 bits): Iden­ti­fies the port number of receiver.

Sequence number (32 bits): The sequence number specifies the first byte of attached payload data or is sent when the con­nec­tion is es­tab­lished or ter­mi­nat­ed. It is also used for val­i­dat­ing and sorting the segments after trans­mis­sion.

Ac­knowl­edg­ment number (32 bits): This field contains the next sequence number that the sender is expecting. An ACK flag (in the “Flags” field) is a pre­con­di­tion for validity.

Offset (4 bits): The “Offset” field specifies the length of the TCP header in 32-bit words to highlight the starting point of the payload data. This starting point varies from segment to segment due to the variable “Options” field.

Reserved (6 bits): Reserved for future use according to RFC 793 and not yet in use. This field must always be set to 0.

Flags (6 bits): The six possible single bits in the “Flags” field enable various TCP actions for or­ga­niz­ing com­mu­ni­ca­tion and data pro­cess­ing. The following flags are either set or not set for these actions:

  • URG: The "Urgent" flag signals to the TCP ap­pli­ca­tion that the payload data must be processed im­me­di­ate­ly up to the set Urgent pointer (see above).
  • ACK: In com­bi­na­tion with the ac­knowl­edg­ment number, the ACK flag ac­knowl­edges the receipt of TCP packets. If the flag is not set, the con­fir­ma­tion number is also invalid.
  • PSH: The "Push" flag ensures that a TCP segment is im­me­di­ate­ly pushed through without first being sent to the buffer of the sender and receiver.
  • RST: If there is an error during trans­mis­sion, a TCP packet with the RST flag set can be used to reset the con­nec­tion.
  • SYN: Messages that have SYN flag set represent the first step of the three-way handshake, meaning they initiate the con­nec­tion.
  • FIN: The "Finish" flag signals to the other party that a sender is ending the trans­mis­sion.

Window size (16 bits): This field specifies the number of bytes that the sender is willing to receive.

Checksum (16 bits): The Trans­mis­sion Control Protocol can reliably detect trans­mis­sion errors. The checksum cal­cu­lat­ed from the header, the payload data and the pseudo-header is used for this purpose.

Urgent pointer (16 bits): The urgent pointer indicates the position of the first byte after the payload data that is to be processed urgently. As a result, this field is only valid and relevant if the URG flag is set.

Options (0 - 320 bits): Use the Options field if you want to include TCP functions that don’t belong in the general header, for example if you want to define the maximum segment size. The length of the options must always be a multiple of 32, otherwise zero-bit padding is required.

How data trans­mis­sion via TCP protocol works in detail

Even before the first data is trans­mit­ted, the sender and receiver typically agree on the maximum size of the TCP segments to be sent (MSS). By default, up to 1,500 bytes per segment are possible, with at least 20 bytes for the TCP header and a further 20 bytes for the IP header, leaving 1,460 bytes for payload data. If you need a custom size, you have to specify it in the Options field as described above, but you’ll have to reduce the payload data ac­cord­ing­ly.

3mds9m7UGVM.jpg To display this video, third-party cookies are required. You can access and change your cookie settings here.

With the maximum segment size minus the headers, a TCP packet can only transmit 1.46 kilobytes or 0.00146 megabytes of data. Seg­men­ta­tion is used to exchange web content like images, which are sometimes several hundred kilobytes in size, via the TCP protocol. In this case, the ap­pli­ca­tion data is divided into several blocks of data before transport, numbered and then sent in random sequence. Since the receiver must ac­knowl­edge the receipt of each segment and can re­con­struct the actual sequence based on the sequence numbers, the receiver can easily com­plete­ly re­assem­ble the received payload data after the TCP trans­mis­sion.

Note

If the sender does not receive ac­knowl­edg­ment for a trans­mit­ted segment, the re­trans­mis­sion timeout (RTO) technique is used. If this timer expires after a packet is sent before a response is trans­mit­ted, the packet is au­to­mat­i­cal­ly re­trans­mit­ted. The duration of the timer is dy­nam­i­cal­ly adjusted by an algorithm and depends on the in­di­vid­ual trans­mis­sion speed.

Summary of key facts about the Trans­mis­sion Control Protocol

The TCP protocol has shaped the history and de­vel­op­ment of computer networks for nearly a half a century. TCP can be easily combined with Internet protocol (IP), which also has a long history, and it has many ad­van­tages over other al­ter­na­tives such as UDP and SCTP. The most important features can be sum­ma­rized as follows:

  • TCP is con­nec­tion-oriented and enables two-way com­mu­ni­ca­tion between two endpoints after the three-way handshake.
  • TCP is reliable because the protocol ensures that all data is fully trans­mit­ted and can be assembled by the receiver in the correct order.
  • TCP allows data to be sent in in­di­vid­ual segments of up to 1,500 bytes (including headers) in size.
  • TCP is po­si­tioned at the transport layer (layer 4) of the OSI model.
  • TCP is usually used in con­junc­tion with the Internet Protocol (IP) and is commonly known as the TCP/IP protocol stack.
  • The TCP header has a default size of 20 bytes. Up to 40 bytes of ad­di­tion­al options can be added.
Go to Main Menu