# Reliable Data Transfer
## What is Reliable Data Transfer
Reliable data transfer is the property of a communication service that guarantees data will be delivered to the destination completely, correctly, and in the original order, regardless of the imperfections of the underlying network. The underlying network is unreliable: packets may be lost, delayed, duplicated, or arrive out of order due to congestion, hardware failures, or routing changes. A reliable data transfer protocol builds reliability on top of this unreliable network by implementing mechanisms to detect and correct these problems.
## Challenges in Reliable Data Transfer
Packet loss occurs when routers drop packets because their buffers are full during congestion or because of hardware errors. The sender must detect when a packet has been lost and retransmit it. Packet corruption occurs when bits in a packet are changed during transmission due to electrical noise or interference. Error detection through checksums allows the receiver to detect corrupted packets and discard them. Packet reordering occurs when packets take different paths through the network and arrive at the destination in a different order than they were sent. The receiver must reorder packets before delivering data to the application. Packet duplication can occur in networks where the same packet is forwarded multiple times due to routing loops or retransmission. The receiver must detect and discard duplicate packets.
## Mechanisms for Reliable Transfer
Checksums allow detection of data corruption. The sender calculates a checksum over the data and includes it in the segment header. The receiver recalculates the checksum and discards the segment if it does not match. Sequence numbers allow the receiver to detect missing, duplicate, and out-of-order segments. Each byte of data is assigned a sequence number, and the receiver uses these numbers to reassemble data in the correct order and to request retransmission of missing data. Acknowledgments allow the sender to know which data has been successfully received. The receiver sends acknowledgments back to the sender indicating the highest sequence number successfully received. Retransmission allows the sender to resend data that was not acknowledged within a timeout period.
## TCP as Reliable Data Transfer
TCP is the primary implementation of reliable data transfer in the TCP/IP suite. It combines all the mechanisms described above. TCP's sequence numbers track every byte of data. Acknowledgments confirm receipt of data up to a certain sequence number. The retransmission timeout is dynamically calculated based on the measured round-trip time. Selective acknowledgments allow precise identification of which data needs to be retransmitted. Together these mechanisms ensure that applications using TCP receive all data exactly once, in the correct order.Back to Subject