# Transport Layer
## What is the Transport Layer in TCP/IP
The Transport layer is the third layer of the TCP/IP model. It provides end-to-end communication services between applications on different hosts. The Transport layer receives data from the Application layer, divides it into smaller units if necessary, adds addressing information to identify which application on the destination host should receive the data, and handles the delivery of this data to the Internet layer for transmission. The two main protocols at the Transport layer of the TCP/IP model are TCP and UDP.
## Transmission Control Protocol
TCP is a connection-oriented, reliable transport protocol. Before data transfer begins, TCP establishes a connection between the source and destination using the three-way handshake. The sender sends a SYN packet indicating it wants to establish a connection. The receiver responds with a SYN-ACK packet acknowledging the connection request. The sender sends an ACK packet completing the handshake. After this, data transfer begins.
TCP provides reliable delivery by requiring the receiver to acknowledge every segment received. If the sender does not receive an acknowledgment within a certain time, it retransmits the unacknowledged segment. Sequence numbers allow the receiver to detect if segments arrive out of order and to reassemble them in the correct sequence. TCP performs flow control using a sliding window mechanism that prevents the sender from overwhelming the receiver. TCP also implements congestion control to reduce transmission rate when the network is congested.
## User Datagram Protocol
UDP is a connectionless, unreliable transport protocol. Unlike TCP, UDP does not establish a connection before sending data. It simply sends each datagram independently without any guarantee of delivery, ordering, or error checking beyond a basic checksum in the UDP header. Because UDP has very little overhead compared to TCP, it is much faster. UDP is used for applications where speed is more important than guaranteed delivery, including DNS queries, DHCP, video streaming, online gaming, and VoIP. For these applications, a small amount of lost data is acceptable, and retransmitting lost packets would introduce unacceptable delays.
## Port Numbers
Both TCP and UDP use port numbers to identify which application on a host is involved in a communication. A combination of an IP address and a port number is called a socket. The source socket and destination socket together uniquely identify a TCP connection. Well-known port numbers below 1024 are assigned to standard services. HTTP uses port 80, HTTPS uses port 443, SSH uses port 22, FTP uses port 21, DNS uses port 53, and SMTP uses port 25. Servers listen on these well-known ports for incoming connections. Client applications use randomly assigned ephemeral port numbers above 1024 for their side of the connection.Back to Subject