What are IP & TCP ?
The Internet Protocol (IP) is the address system of the Internet and has the core function of delivering packets of information from a source device to a target device. IP is the primary way in which network connections are made, and it establishes the basis of the Internet. IP does not handle packet ordering or error checking. Such functionality requires another protocol, often the Transmission Control Protocol (TCP).
The TCP/IP relationship is similar to sending someone a message written on a puzzle through the mail. The message is written down and the puzzle is broken into pieces. Each piece then can travel through a different postal route, some of which take longer than others. When the puzzle pieces arrive after traversing their different paths, the pieces may be out of order. IP makes sure the pieces arrive at their destination address. TCP can be thought of as the puzzle assembler on the other side who puts the pieces together in the right order, asks for missing pieces to be resent, and lets the sender know the puzzle has been received. TCP maintains the connection with the sender from before the first puzzle piece is sent to after the final piece is sent.
IP is a connectionless protocol, which means that each unit of data is individually addressed and routed from the source device to the target device, and the target does not send an acknowledgement back to the source. That’s where protocols such as TCP come in. TCP is used in conjunction with IP in order to maintain a connection between the sender and the target and to ensure packet order.
TCP 3-way Handshake →
The TCP 3-Way Handshake is a process used by the Transmission Control Protocol (TCP) to establish a reliable connection between a client and a server before data transfer. It ensures that both sides are synchronized and ready to communicate.
How data transfer works →
For example, when an email is sent over TCP, a connection is established and a 3-way handshake is made. First, the source sends an SYN “initial request” packet to the target server in order to start the dialogue. Then the target server sends a SYN-ACK packet to agree to the process. Lastly, the source sends an ACK packet to the target to confirm the process, after which the message contents can be sent. The email message is ultimately broken down into packets before each packet is sent out into the Internet, where it traverses a series of gateways before arriving at the target device where the group of packets are reassembled by TCP into the original contents of the email.

The primary version of IP used on the Internet today is Internet Protocol Version 4 (IPv4). Due to size constraints with the total number of possible addresses in IPv4, a newer protocol was developed. The newer protocol is called IPv6. It makes many more addresses available and is increasing in adoption.
TCP connection termination
TCP connection termination is the process of closing an established TCP connection between two devices in an orderly way. It uses a four-step handshake (FIN-ACK exchange) to ensure that both sides have finished sending and receiving all data before the connection is fully closed.

How mechanism works In TCP connection termination :
Step 1 (FIN from Client): The client sends a FIN to the server to start closing and enters the FIN_WAIT_1 state.
Step 2 (ACK from Server): The server acknowledges the FIN and the client moves to FIN_WAIT_2.
Step 3 (Client Waiting): The client waits for the server’s FIN while in the FIN_WAIT_2 state.
Step 4 (FIN from Server): The server sends its FIN after completing its closing tasks.
Step 5 (ACK from Client): The client acknowledges the server’s FIN, enters TIME_WAIT, and after a set delay, the connection closes fully.
TCP solves Data Reliability, Order, and Correctness
Ordered data transfer: the destination host rearranges segments according to a sequence number
Retransmission of lost packets: any cumulative stream not acknowledged is retransmitted
Error-free data transfer: corrupted packets are treated as lost and are retransmitted
Flow control: limits the rate a sender transfers data to guarantee reliable delivery. The receiver continually hints the sender on how much data can be received. When the receiving host's buffer fills, the next acknowledgment suspends the transfer and allows the data in the buffer to be processed.
Congestion control: lost packets (presumed due to congestion) trigger a reduction in data delivery rate
