TCP basics
What is TCP?
TCP stands for Transmission Control Protocol. It’s one of the core protocols of Internet Protocol(IP) suite. TCP ensures reliable, ordered, and error-checked delivery of data between applications running on devices connected to a network.
Why is TCP useful?
Without TCP, data sent over the internet could arrive out of order, get lost, or be duplicated. So TCP solves this by * Breaking data into Packets. * Ensuring all packets arrive correctly and in order. * Retransmitting lost packets. * This makes it ideal for applications where accuracy and reliability are critical like web browsing, email.
How it works?
Connection setup (3-way handshake) – The client and server exchange messages to establish a connection.
Data transfer – Data is broken into packets, sent, acknowledged, and reassembled in the correct order.
Error checking – TCP checks for errors and requests retransmission if needed.
Connection termination – Once data transfer is complete, the connection is closed gracefully.
Where is TCP used?
Web browsing – HTTP and HTTPS use TCP to load websites reliably.
Email – Protocols like SMTP, IMAP, and POP3 rely on TCP.
File transfers – FTP and other file-sharing tools use TCP for accurate data delivery.
Remote access – SSH and Telnet use TCP to ensure secure and reliable sessions.
Why OSI Layer: Transport Layer (Layer 4)?
It manages end-to-end communication between devices.
It handles segmentation, flow control, error correction, and retransmission.
It provides a reliable communication channel for applications running at the Application Layer (Layer 7).
What are the key features?
Connection-oriented.
Reliable data transfer.
Error detection and recovery.
What is a three-way handshake in TCP?
A process used to establish a TCP connection: * SYN – Client sends a synchronize request. * SYN-ACK – Server acknowledges and synchronizes. * ACK – Client acknowledges server’s response.
What is a TCP segment?
A TCP segment is the unit of data sent over a TCP connection. It consists of: * TCP header (including sequence number, acknowledgment number, flags, etc.). * Data payload.
How is retransmission handled in TCP?
If an ACK is not received within the timeout interval, TCP retransmits the segment. Modern TCP uses: * Timeout-based retransmission. * Fast retransmit (based on duplicate ACKs).
What are some applications that use TCP?
HTTP/HTTPS (Web).
FTP (File Transfer).
SMTP (Email).
Telnet / SSH (Remote Access).
What is the working flow of TCP?
Connection Establishment (3-Way Handshake): * Client sends SYN → Says I want to start a connection. * Server replies with SYN-ACK → Says Okay, I got it. Let’s sync. * Client sends ACK → Says Confirmed. Let’s communicate.
Data Transfer: * Data is broken into segments with sequence numbers. * Each segment is sent from sender to receiver. * Receiver sends ACKs back to confirm receipt. * TCP uses a sliding window to send multiple packets before waiting. * If data is lost or corrupted, TCP retransmits it. * Flow control makes sure the sender doesn’t overload the receiver. * Congestion control adjusts speed based on network traffic.
Connection Termination (4-Way Handshake): * Sender sends FIN → Says I’m done sending data. * Receiver sends ACK → Says Okay, I got it. * Receiver sends FIN → Says I’m done too. * Sender sends ACK → Says Goodbye.
What is the difference between a port and an IP address?
IP address identifies a host in the network.
Port number identifies a specific process/service on that host. Together (IP + Port) = Socket.
Is TCP Windows specific?
No, TCP is not Windows-specific.
TCP is a standard protocol used across multiple platforms, including Windows, Linux, macOS, and others.
It is implemented in virtually all modern operating systems and is fundamental to networking.
Is TCP Linux specific?
No, TCP is not Linux-specific.
TCP is supported by all major operating systems, including Linux, Windows, macOS, and others.
It is the core protocol for reliable communication in most networks across different platforms.
Which Transport Protocol is used by TCP?
TCP (Transmission Control Protocol) itself is a transport layer protocol.
It provides reliable, connection-oriented communication between devices over a network.
TCP ensures data delivery and integrity by establishing a connection before transmitting data.
Which Port is used by TCP?
TCP does not use a specific port by itself.
However, applications using TCP assign specific port numbers for communication (e.g., HTTP uses port 80, HTTPS uses port 443).
Port numbers are assigned to different services and applications to ensure correct routing of data.
Is TCP using Client-server model?
Yes, TCP follows the client-server model.
The client sends a request to a server over a TCP connection, and the server responds to that request.
TCP ensures reliable data transfer between the client and server by establishing a connection before data exchange.
In this section, you are going to learn
Terminology
Version Info
TCP Version |
RFC |
Year |
Core Ideas/Contribution |
---|---|---|---|
TCP v1 |
|||
RFC 675 |
1974 |
First specification of TCP,combined with IP; intial handshake |
|
concept introduced . |
|||
TCP v2 |
|||
RFC 761 |
1980 |
Defined TCP separately from IP and updated segment formats. |
|
TCP v3(stable TCP) |
|||
RFC 793 |
1981 |
The foundational TCP specifications; still forms the backbone |
|
of modern TCP implementations. |
|||
TCP Performance Extensions |
|||
RFC 1323 |
1992 |
Intoduction of Window scaling,timestamps and PAWS. |
|
TCP SACK |
|||
RFC 2018 |
1996 |
Selective retransmission based on ACKs of received blocks. |
|
TCP Congestion Control |
|||
Algorithm |
|||
RFC2581 |
1999 |
Defined algorithms like slow start, fast retransmit , congestion |
|
avoidance. |
|||
TCP ECN Support |
|||
RFC3168 |
2001 |
Enabled routers to signal congestion without packet loss. |
|
Modern Congestion Control |
|||
update |
|||
RFC5681 |
2009 |
superseded RFC2581 with more robust congestion recovery |
|
mechanisms. |
|||
TCP Fast open (TFO) |
|||
RFC7413 |
2014 |
Reduced Web Latency; improved Performance for short, |
|
repeated TCP connections |
|||
Updated TCP specification |
|||
RFC9293 (RFC 793bis) |
2021 |
clarified outdated parts of RFC 793; incorporated decades of |
|
extensions and best practices. |
setup
setup
TCP SYN Packet
S.No |
Protocol Packets |
Description |
Size(bytes) |
---|---|---|---|
1 |
SYN Packet |
Used to initiate a TCP connection. It is part of the |
18 |
three-way handshake process. |
|||
Source Port |
port number of the sender(Client) |
2 |
|
Destination Port |
port number of the receiver |
2 |
|
Sequence Number |
Initial sequence number |
4 |
|
Acknowledgment Number |
0(not set) |
0 |
|
Data Offset |
4-bit field that specifies size of TCP header in |
1 |
|
32-bit words. |
|||
Reserved |
3 bits reserved for future purpose |
1 |
|
Flags |
SYN flag set |
2 |
|
Window Size |
Size of the sender’s receive window. |
2 |
|
Checksum |
Error-checking field. |
2 |
|
Urgent Pointer |
points to the urgent data if the URG flag is set. |
2 |
|
Options |
May include options like Maximum Segment Size,Window scaling,Timestamps. |
variable |
|
Data(Payload) |
does not carry any payload data. |
0 |
TCP SYN-ACK Packet
s.no |
Packet details |
descrption |
size(Bytes) |
---|---|---|---|
2 |
SYN-ACK Packet |
Sent by the receiver to acknowledge the SYN |
22 |
packet and establish the connection. |
|||
Source Port |
port number of the receiver |
2 |
|
Destination Port |
port number of the sender(Client) |
2 |
|
Sequence Number |
server’s ISN(Initial sequence number) |
4 |
|
Acknowledgment Number |
Client’s ISN+1 |
4 |
|
Data Offset |
4-bit field that specifies size of TCP header in |
1 |
|
32-bit words. |
|||
Reserved |
3 bits reserved for future purpose |
1 |
|
Flags |
SYN=1, ACK=1 |
2 |
|
Window Size |
Size of the receiver’s receive window. |
2 |
|
Checksum |
Error-checking field. |
2 |
|
Urgent Pointer |
points to the urgent data if the URG flag is set. |
2 |
|
Options |
May include options like Maximum Segment Size,Window scaling,Timestamps. |
variable |
|
(MSS). |
|||
Data(Payload) |
does not carry any payload data. |
0 |
TCP ACK Packet
s.no |
Packet details |
descrption |
size(bytes) |
---|---|---|---|
3 |
ACK Packet |
Used to acknowledge received data or control packets. |
22 |
Source Port |
port number of the sender(Client) |
2 |
|
Destination Port |
port number of the receiver |
2 |
|
Sequence Number |
next byte the sender expects to receive. |
4 |
|
Acknowledgment Number |
Sequence number of the last received byte + 1. |
4 |
|
Data Offset |
4-bit field that specifies size of TCP header in |
1 |
|
32-bit words. |
|||
Reserved |
3 bits reserved for future purpose |
1 |
|
Flags |
ACK=1 |
2 |
|
Window Size |
Size of the Sender’s receive window. |
2 |
|
Checksum |
Error-checking field. |
2 |
|
Urgent Pointer |
points to the urgent data if the URG flag is set. |
2 |
|
Options |
May include options like Maximum Segment Size,Window scaling,Timestamps. |
variable |
|
(MSS). |
|||
Data(Payload) |
can carry payload data if it is piggybacking on data being sent. |
variable |
TCP SUBSCRIBE Packet
TCP PSH-ACK Packet
s.no |
packet details |
descrption |
size(bytes) |
---|---|---|---|
4 |
PSH-ACK Packet |
Used to push data immediately to the receiving |
22 |
application and acknowledge the receipt of data. |
|||
Source Port |
port number of the sender(Client) |
2 |
|
Destination Port |
port number of the receiver |
2 |
|
Sequence Number |
sequence number of the first byte of data in the current |
4 |
|
message. |
|||
Acknowledgment Number |
sequence number of the next byte that the sender is |
4 |
|
expecting to receive. |
|||
Data Offset |
4-bit field that specifies size of TCP header in |
1 |
|
32-bit words. |
|||
Reserved |
3 bits reserved for future purpose |
1 |
|
Flags |
PSH=1, ACK=1 |
2 |
|
Window Size |
Size of the Sender’s receive window. |
2 |
|
Checksum |
Error-checking field. |
2 |
|
Urgent Pointer |
points to the urgent data if the URG flag is set. |
2 |
|
Options |
May include options like Maximum Segment Size,Window scaling,Timestamps. |
variable |
|
(MSS). |
|||
Data(Payload) |
carries payload data that needs to be processed immediately by the receiving application |
variable(1460) |
TCP FIN Packet
s.no |
packet details |
descrption |
size(Bytes) |
---|---|---|---|
5 |
FIN Packet |
Used to terminate a TCP connection. |
22 |
Source Port |
port number of the sender(Client) |
2 |
|
Destination Port |
port number of the receiver |
2 |
|
Sequence Number |
Sequence number of the last byte sent. |
4 |
|
Acknowledgment Number |
Acknowledges received data |
4 |
|
Data Offset |
4-bit field that specifies size of TCP header in |
1 |
|
32-bit words. |
|||
Reserved |
3 bits reserved for future purpose |
1 |
|
Flags |
FIN=1 |
2 |
|
Window Size |
Size of the Sender’s receive window. |
2 |
|
Checksum |
Error-checking field. |
2 |
|
Urgent Pointer |
points to the urgent data if the URG flag is set. |
2 |
|
Options |
May include options like Maximum Segment Size,Window scaling,Timestamps. |
variable |
|
(MSS). |
|||
Data(Payload) |
does not carry any payload data. |
0 |
TCP FIN-ACK Packet
S.No |
Packets details |
Description |
Size(bytes) |
---|---|---|---|
6 |
FIN-ACK Packet |
Sent to acknowledge the receipt of a FIN packet and |
22 |
signal the end of data transmission. |
|||
Source Port |
port number of the sender(Client) |
2 |
|
Destination Port |
port number of the receiver |
2 |
|
Sequence Number |
Sequence number of the last byte sent. |
4 |
|
Acknowledgment Number |
sequence number of the next byte that the sender is expecting to receive |
4 |
|
Data Offset |
4-bit field that specifies size of TCP header in |
1 |
|
32-bit words. |
|||
Reserved |
3 bits reserved for future purpose |
1 |
|
Flags |
FIN=1,ACK=1 |
2 |
|
Window Size |
Size of the Sender’s receive window. |
2 |
|
Checksum |
Error-checking field. |
2 |
|
Urgent Pointer |
points to the urgent data if the URG flag is set. |
2 |
|
Options |
May include options like Maximum Segment Size,Window scaling,Timestamps. |
variable |
|
(MSS). |
|||
Data(Payload) |
does not carry any payload data. |
0 |
TCP RST Packet
s.no |
packet details |
descrption |
size(bytes) |
---|---|---|---|
7 |
RST Packet |
Used to reset a TCP connection. |
22 |
Source Port |
port number of the sender(Client) |
2 |
|
Destination Port |
port number of the receiver |
2 |
|
Sequence Number |
Sequence number of the last byte sent. |
4 |
|
Acknowledgment Number |
Typically set to 0, as the connection is being reset. |
4 |
|
Data Offset |
4-bit field that specifies size of TCP header in |
1 |
|
32-bit words. |
|||
Reserved |
3 bits reserved for future purpose |
1 |
|
Flags |
RST=1 |
2 |
|
Window Size |
Size of the Sender’s receive window. |
2 |
|
Checksum |
Error-checking field. |
2 |
|
Urgent Pointer |
points to the urgent data if the URG flag is set. |
2 |
|
Options |
May include options like Maximum Segment Size,Window scaling,Timestamps. |
variable |
|
(MSS). |
|||
Data(Payload) |
does not carry any payload data. |
0 |
TCP-Use Cases |
||
---|---|---|
S.No |
Use Case |
Descrption |
1 |
Web Browsing(HTTP/HTTPS) |
Ensures reliable delivery of web pages & resources over protocols. |
2 |
Email(SMTP, IMAP,POP3) |
Guarantees ordered and complete message delivery for sending |
and retrieving emails. |
||
3 |
File Transfer(FTP,SFTP) |
Reliable and ordered transmission of large files over networks. |
4 |
Data Base Access |
Maintains consistent & reliable connections for updating data base. |
5 |
VoIP with TCP fallback |
Some VoIP appilications use TCP for control/data fall back. |
6 |
IOT Device Control |
Requiring reliable communication between IOT devices . |
S.No |
Feature |
Descrption |
---|---|---|
1 |
Connection-oriented |
Enables a reliable communication b/w sender & receiver. |
2 |
Reliable Data Transfer |
Ensures data is delivered accurately and in order using ACks and |
retransmissions. |
||
3 |
Error Detection |
Uses checksum to detect corrupted data segments in transmission. |
4 |
Flow Control |
Prevents overwhelming receiver using the sliding Window protocol. |
5 |
Port Addressing |
Uses port numbers to identify sending and receiving appilications on |
hosts. |
||
6 |
Graceful Connection Termination |
Closes connections cleanly using a 4-step termination process. |
7 |
Congestion Control |
Adjusts transmission rate based on network congestion using |
algorithms like slow start and congestion avoidance. |
||
8 |
Stream-Oriented |
Treats data as a continous byte stream rather than discrete packets. |
9 |
Ordered Delivery |
Reassembles segments in the correct order before passing data to |
the appilication layer. |
S.No |
Protocol/Application |
Descrption |
---|---|---|
1 |
HTTP/HTTPS |
|
2 |
FTP(File Transfer Protocol) |
Transfers files between client and server with control and data channels over TCP |
3 |
SMTP |
Sends emails between mail servers using reliable TCP connections. |
4 |
DNS(Zone Transfer Only) |
Zone Transfers(AXFR) use TCP for reliability. |
5 |
IMAP/POP3 |
Retrieves emails from mail servers while ensuring message integrity. |
6 |
SSH |
Provides secure remote login and command execution over encrypted TCP sessions. |
7 |
Telnet |
Allows remote terminal access over TCP. |
8 |
SFTP(SSH File Transfer Protocol) |
Securly transfer files over SSH,which runs over TCP. |
9 |
LDAP over TCP |
Directory services often run over TCP to support reliable data access. |
Reference links