What is TCP (Transmission Control Protocol)?

A connection-oriented transport-layer protocol. It sets up a connection with a three-way handshake and uses sequence numbers, acknowledgments (ACKs) and retransmission to deliver data in order, without gaps or duplicates. Flow control and congestion control adjust how much it sends. It carries web traffic over HTTP/1.1 and HTTP/2, email, SSH and more.

Japanese name: TCP

TCP (Transmission Control Protocol) appears in 17 practice questions across 2 topics, including Computer Networking Basics, Web Technology Basics.

Field: Computer Networking Basics

How TCP guarantees delivery

TCP gives every byte it sends a running number, the sequence number. The receiver returns an acknowledgment (ACK) that says, in effect, send me the data starting from this number next. If no ACK arrives within a set time, the sender sends the data again (retransmission timeout). If it receives three ACKs with the same number (duplicate ACKs), it retransmits without waiting for the timeout (fast retransmit). The receiver puts data that arrived out of order back in order, discards duplicates and uses a checksum to detect corrupted data. To the application, the data looks like a continuous stream of bytes with no message boundaries.

Windows decide how much to send

The sender may send up to a window's worth of data before it has to wait for ACKs. Matching the free buffer space the receiver advertises (the receive window) is flow control; growing and shrinking the sender's congestion window to match how busy the network is, is congestion control. The sender uses whichever of the two is smaller. Because only one window of data can be sent per round-trip time (RTT), throughput is roughly window ÷ RTT. With a 64 KB window and a 100 ms RTT, for example, the ceiling is about 5 Mbit/s, so fast long-distance links rely on the window scale option to allow larger windows.

Header and connection management

A TCP header is 20 bytes without options. It holds the source and destination port numbers, the sequence number, the acknowledgment number, flags such as SYN, ACK, FIN and RST, the window size and a checksum. A connection is identified by four values: the source and destination IP addresses and port numbers. It opens with a three-way handshake and closes when each direction sends a FIN. If one segment is lost, later data cannot be passed to the application even if it has arrived (head-of-line blocking), which is one reason HTTP/3 uses QUIC over UDP instead.

Try it: questions about TCP (Transmission Control Protocol)

In the four-layer TCP/IP model, which layer do TCP and UDP belong to?

  1. AApplication layer
  2. BInternet layer
  3. CTransport layer
Show answer and explanation

Answer: C. Transport layer

The TCP/IP model is described with four layers, from the bottom: the link layer (network interface layer), the internet layer, the transport layer and the application layer. TCP and UDP are transport-layer protocols, and they use port numbers to tell which application on a host the traffic is for. IP, in the internet layer, is responsible for delivering packets from one host to another. HTTP and DNS are application-layer protocols. Mapped onto the OSI reference model, the transport layer corresponds to layer 4 and the internet layer to layer 3.

In the three-way handshake that establishes a TCP connection, what is the correct order of the packets exchanged?

  1. ASYN → ACK → FIN
  2. BACK → SYN → SYN+ACK
  3. CSYN → SYN+ACK → ACK
Show answer and explanation

Answer: C. SYN → SYN+ACK → ACK

In the three-way handshake, the client first requests a connection with a SYN and announces the first number of the data it will send (its initial sequence number). The server replies with a SYN+ACK, acknowledging (ACK) that and announcing its own initial sequence number. Finally the client returns an ACK, and both directions are ready. Confirming the numbers in both directions in three exchanges prevents mistaken connections, for example from old packets that arrive late. As a result, TCP needs at least one round-trip time (RTT) before data can start flowing. FIN is used to close a connection.

FAQ

What is the difference between TCP and UDP?

TCP sets up a connection and delivers data reliably with acknowledgments, retransmission and ordering. UDP has no setup and no retransmission and simply sends datagrams, so its header is smaller and it adds less delay. TCP is used where completeness matters, such as the web and file transfer; UDP is used where low delay matters more than an occasional loss, such as voice calls, and for short exchanges such as DNS queries.

When does TCP retransmit?

There are two triggers: no ACK arriving before the retransmission timeout, which is calculated from measured RTTs, and three duplicate ACKs with the same acknowledgment number in a row, which triggers fast retransmit. If retransmissions keep failing, the timeout is doubled each time.

Why is TCP throughput lower than the link speed?

At most one window of data can be sent per round-trip time, so throughput falls as the distance to the other end grows or as the window shrinks. It also drops when packet loss makes congestion control cut the window, or when the receiving application reads data slowly.

TCP (Transmission Control Protocol) in the explanations

Questions that mention TCP (Transmission Control Protocol) (17)

  1. In the four-layer TCP/IP model, which layer do TCP and UDP belong to?
  2. In the three-way handshake that establishes a TCP connection, what is the correct order of the packets exchanged?
  3. A client makes a new HTTPS connection (TLS 1.3 over TCP) to a web server with a round-trip time (RTT) of 100 ms. Roughly how long does it take until the response to the first request starts to arrive? Assume DNS resolution is already done, and ignore server processing time and data transfer time.
  4. In TCP flow control, what is the purpose of the receiver advertising its window size (receive window) to the sender?
  5. A TCP connection has a fixed receive window of 65536 bytes and an RTT of 10 ms. The link bandwidth is ample and there is no loss. Which is closest to the upper limit on this connection's throughput?
  6. Which correctly describes the basic idea of TCP congestion control?
  7. What triggers a TCP sender to decide that a segment was lost and retransmit it?
  8. On 1 Gbps Ethernet, TCP data is sent continuously with IP packets filling the 1500-byte MTU. Taking the IPv4 header as 20 bytes, the TCP header as 20 bytes, the Ethernet header and FCS together as 18 bytes, and the preamble and inter-frame gap together as 20 bytes, which is closest to the upper limit on application-data throughput?
  9. From a web server with an RTT of 40 ms, one HTML file and the four images it references are fetched one after another. Assume that establishing a TCP connection takes one round trip and each request and response take one round trip, and ignore data transfer time, server processing time, TLS and connection teardown. Which of the following is the difference in total time between opening a new TCP connection for each object and reusing one TCP connection (a persistent connection)?
  10. 1.5 MB of text data is compressed with gzip to one third of its size and sent. The bandwidth is 10 Mbps and the RTT is 100 ms, and before the data starts to be sent, the TCP connection, the TLS handshake and the HTTP request take three round trips in total. Assume 1 MB = 10^6 bytes, and ignore compression and decompression time, headers and waiting caused by TCP congestion control. Which of the following is closest to the time until all the data has been received?
  11. In the OSI reference model, which layer uses logical addresses such as IP addresses to relay packets between different networks until they reach their destination?
  12. When a web page's data is sent, what happens on the sending side each time the data is passed from an upper layer to a lower layer?
  13. Which correctly describes UDP?
  14. What is the main role of DNS (Domain Name System)?
  15. Roughly how long does it take to send a 100 MB file over a 100 Mbps link? Ignore overhead such as headers and latency, and take 1 MB = 10^6 bytes.

Books on Computer Networking Basics Ad

As an Amazon Associate I earn from qualifying purchases.

Comparisons that include this term

Related terms

Packet HTTP (Hypertext Transfer Protocol) Round-trip time (RTT) IP (Internet Protocol) UDP (User Datagram Protocol) DNS (Domain Name System) TLS QUIC Congestion control Router

Back to the glossary