TCP Working: 3-Way Handshake & Reliable Communication

1. Why Do We Even Need Rules on the Internet?
Imagine sending messages without any agreement on:
who sends first
whether the message arrived
what happens if part of it is lost
That is exactly what would happen if computers sent data without protocols.
The internet works because every device follows a common set of rules.
These rules are provided by TCP/IP.
2.What is TCP and Why Is It Needed?
TCP (Transmission Control Protocol) is a transport-layer protocol used for reliable communication between devices over a network.
Its job is not to find where data should go (that’s IP’s role), but to ensure:
data reaches the destination
data arrives in order
missing data is detected and resent
communication starts and ends properly
TCP is used in applications where accuracy matters, such as:
web browsing (HTTP/HTTPS)
file transfers
emails
APIs and backend communication

3. Problems TCP Is Designed to Solve
If data were sent without TCP, several problems would occur:
Data loss – packets may disappear during transmission
Out-of-order delivery – packets may arrive shuffled
Duplicate packets – same data may arrive multiple times
No confirmation – sender wouldn’t know if data arrived
Uncontrolled flow – receiver could be overwhelmed
TCP exists specifically to solve these issues.
Connection Establishment and Termination
1. Connection Establishment (Three-Way Handshake)
TCP is connection-orientated, meaning a connection must be established before any data is sent. This is done using a three-way handshake:

SYN (Synchronize): The sender sends a SYN segment to the receiver to request a connection.
SYN-ACK (Synchronize-Acknowledge): The receiver responds with a SYN-ACK segment, acknowledging the request and agreeing to the connection.
ACK (Acknowledge): The sender replies with an ACK, confirming the connection is established.
This process ensures both sender and receiver are ready and synchronized, preventing lost or misordered data at the start.
2. Connection Termination (Four-Way Handshake)

Closing a TCP connection requires a four-step handshake to ensure both sides finish transmitting data safely:
FIN (Finish): The sender who wants to close the connection sends a FIN segment to the receiver.
ACK (Acknowledge): The receiver acknowledges the FIN with an ACK.
FIN (Finish) from Receiver: The receiver then sends its own FIN when it is ready to close the connection.
ACK (Acknowledge): The sender responds with an ACK, completing the termination.
This ensures that all remaining data is transmitted before the connection is fully closed.
For more detailed 3 way Handshaking understanding refer to (LINK)
What If Data Is Lost?
Data loss is normal on the internet, and TCP handles it automatically.
Here’s what happens.
Packet Loss and Retransmission

The lost data is resent automatically. All of this happens in the background — the user never notices, and the website still works fine.
Advantages of TCP
Error-Free Data Transfer: TCP detects errors during transmission and retransmits lost or corrupted data, ensuring accurate delivery.
Ordered Delivery: Data packets are received in the same sequence in which they were sent, maintaining data consistency.
Flow Control: Prevents the sender from overwhelming the receiver by controlling the rate of data transmission.
Congestion Control: Adjusts the sending speed based on network traffic conditions to reduce packet loss and congestion.
Reliable Communication: Ensures complete and dependable data transfer, making it suitable for critical applications.
Widely Supported and Standardized: TCP is a globally accepted protocol, supported by all major operating systems and network devices.




