Reliable data delivery is accomplished by transmitting sequence numbers with all packets, and acknowledging up to which octet offset the receiver has seen the stream. This gives the sender the ability to retransmit lost packets, while the receiver can recover correct sequence if reordering has occured. If acknowledgments or other required responses don't come back, TCP will try retransmitting for a while but eventually it'll time out and notify the application about the failure. Flow control is accomplished by a window being advertised by the receiver. This gives the receiver ability to throttle the sender down to a rate that the receiver can accept.
Congestion control is somewhat more involved.
The sender keeps track of a parameter called congestion window . The effective window is than the minimum of receiver-advertised window and the congestion window. It's typically an exponentially decaying running average of observed round-trip times. Once the first packet loss is detected, slow start is over and the normal phase begins. Loss detection is based upon receiving three duplicates of the same acknowledgment or non-arrival of acknowledgments within a given time frame.