TCP Overview

Okan Özşahin
5 min readOct 15, 2023

Transmission Control Protocol is a fundamental protocol for point-to-point communication, typically used in scenarios with one sender and one receiver. Here’s an overview of some of its key characteristics:

1. Reliable, In-Order Byte Stream: TCP ensures that data is transmitted reliably and in the correct order. It achieves this by dividing the data into segments, numbering them, and then reassembling them at the receiver’s end. This means that there are no strict “message boundaries” in TCP; it deals with a continuous stream of bytes.

2. Full Duplex Data: TCP supports full-duplex communication, meaning data can flow bidirectionally within the same connection. Both the sender and receiver can transmit data simultaneously, allowing for efficient two-way communication.

3. Maximum Segment Size (MSS): TCP segments data into packets, and the Maximum Segment Size (MSS) is the largest amount of data that can be sent in a single segment. The MSS is negotiated during the TCP handshake and depends on the maximum transmission unit (MTU) of the network.

4. Cumulative ACKs: TCP uses acknowledgment (ACK) packets to confirm the receipt of data segments. These ACKs are cumulative, meaning they acknowledge the receipt of all data up to a specific sequence number, which helps in avoiding unnecessary retransmissions.

5. Pipelining: TCP employs pipelining to maximize network efficiency. It allows multiple data segments to be in transit simultaneously, without waiting for individual acknowledgments. This improves throughput and reduces the impact of latency.

6. Connection-Oriented: TCP is connection-oriented, which means that it begins with a handshake process where both the sender and receiver exchange control messages to establish a connection. This connection setup ensures that both parties are in the correct state to start data transmission.

7. Flow Control: TCP implements flow control mechanisms to prevent the sender from overwhelming the receiver with data. It uses a sliding window approach to regulate the amount of data that can be in transit at any given time, adjusting the window size based on the receiver’s ability to handle incoming data.

TCP sequence numbers, ACKs

TCP uses sequence numbers and acknowledgments (ACKs) to ensure reliable and in-order data transmission. Here’s a brief explanation of how they work:

Sequence Numbers:
- Sequence numbers in TCP represent the byte stream “number” of the first byte in a segment’s data. Each TCP segment is assigned a sequence number, and these sequence numbers are used to reassemble data at the receiver in the correct order.
- For example, if a sender sends a stream of data, the segments might have sequence numbers like 1000, 1200, 1400, and so on, indicating the position of the first byte in the segment within the overall data stream.

Acknowledgments (ACKs):
- ACKs in TCP represent the sequence number of the next byte expected from the other side. In other words, an ACK acknowledges the receipt of all bytes up to and including the specified sequence number.
- For example, if the receiver has successfully received all data up to byte 1400 in the above example, it will send an ACK with the sequence number 1401. This tells the sender that it expects the next byte to be 1401.

Regarding how the receiver handles out-of-order segments, you’re correct in noting that the TCP specification doesn’t explicitly define the behavior. Instead, it leaves it up to the implementor to decide how to handle out-of-order segments. In practice, most TCP implementations are designed to reassemble the data in the correct order at the receiver’s end before passing it to the upper layers of the protocol stack. This reordering is typically done using buffering and tracking of received segments based on their sequence numbers.

I would like to briefly touch on the go back n protocol as it is related to what I explained above. Wecan think TCP like this that use go-back-n protocol:

Go-Back-N is an automatic repeat request (ARQ) protocol used in data communication to ensure reliable data transmission over an unreliable channel, often employed in scenarios like point-to-point communication using protocols like TCP. Go-Back-N is one of the two primary ARQ protocols, the other being Selective Repeat.

Go-Back-N relies on a sliding window approach, where the sender can transmit a sequence of data frames before needing an acknowledgment (ACK) from the receiver. If a frame is lost or received with errors, the sender “goes back” to the beginning of the window and retransmits all the frames from that point onward.

Here’s how Go-Back-N works in action:

1. Sender-Side:

- The sender maintains a sending window, which is a range of sequence numbers for which it can send data frames.

- The sender sends a series of data frames with sequence numbers within the window.

- After sending the frames, it waits for ACKs from the receiver.

2. Receiver-Side:

- The receiver also maintains a window called the receiving window. It’s used to track the expected sequence numbers of incoming frames.

- The receiver receives data frames and checks their sequence numbers. If a frame is within the receiving window and is error-free, it’s accepted, and an ACK is generated.

- If a frame is outside the receiving window or has errors, it is discarded. The receiver does not generate ACKs for these frames.

3. Sender Handling ACKs:

- When the sender receives an ACK, it knows that all frames with sequence numbers up to and including the acknowledged frame have been received successfully by the receiver.

- The sender then moves its sending window to the next unacknowledged frame and continues sending new frames.

4. Loss or Error Handling:

- If the sender’s timer expires before it receives an ACK for a particular frame, it assumes that the frame was lost or damaged in transit and retransmits all unacknowledged frames from the beginning of the window.

- This “goes back” action is the key feature of Go-Back-N. It allows the sender to retransmit a group of frames upon a single timeout, which can be more efficient than retransmitting just the lost frame.

5. Advancement of the Receiving Window:

- As the receiver successfully receives frames and generates ACKs, it advances its receiving window.

- This means the receiver can accept frames with sequence numbers within the new window range.

6. Continuous Process:

- The process of sending, receiving, and acknowledging frames continues, creating a continuous flow of data.

Go-Back-N provides efficient error recovery by sending multiple frames before requiring acknowledgments and having the sender retransmit a group of frames upon a single error detection. However, Go-Back-N assumes that frames are delivered in order, and out-of-sequence frames are discarded. In cases where out-of-order delivery can occur, the Selective Repeat ARQ protocol is a more suitable choice.

In summary, sequence numbers and cumulative ACKs are key mechanisms used by TCP to manage data transmission and ensure reliability. Handling out-of-order segments is not explicitly specified in the TCP specification, but most implementations reassemble data in the correct order for delivery to the receiving application.



Okan Özşahin

Backend Developer at hop | Civil Engineer | MS Computer Engineering