Hi all, today in my blog post, we will take a deep dive into the heart of the OSI (Open System Interconnection) Model — the Transport Layer, one of its most critical components. First, we’ll discuss what the Transport Layer is and why it is important. Then, we’ll explore the difference between TCP and UDP, the protocols of the Transport Layer. So, let’s get started and explore this topic together!
What is the Transport layer and why it is important?
OSI (Open System Interconnection) has 7 layers and Transport layer is the most important one because it sits at position number 4 in the middle of the 7 layers of OSI. Transport layer acts as a bridge between the Application layer (top 3 layers) and the Network layer (bottom 3 layers). Transport layer ensures that the flow of data is smoothly access across the layers generated by the Application Layer and also ensures that it also prevents data overflow by managing the rate of data transmission based on the receiver’s capacity. Apart from connection layers, Transport layer also ensures reliable communication by managing error detection and correction and it also guarantees that the data reaches its destination without any problem, Transport layer do this by breaking down the larger packets data into smaller segments for efficient transmission and reassembles them at the receiver’s end. The common protocol used by the Transport Layer is TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) and in the next section we will discuss about the difference between TCP and UDP.
TCP vs UDP
In this section, we will discuss the difference between TCP and UDP
Connection:-
TCP is a connection-oriented protocol, meaning a connection must be established for communication. In TCP, a connection is established through the 3-Way Handshake with SYN, ACK, and SYN-ACK messages, and the connection is terminated using the 4-Way Handshake with FIN and ACK messages from both sides. On the other hand, UDP is connectionless, meaning no connection needs to be established for communication.
Speed:-
If we compare the speed of these two protocols, then UDP wins the race because it is faster due to being connectionless and having no ACK mechanism for guaranteed transfer. On the other hand, TCP is slower because of its additional mechanisms. So, if you need fast communication and if some losses are not important to you, you can use User Datagram Protocol. But if guaranteed transfer is your number one priority, then you should use Transmission Control Protocol, even though it is slower than UDP.
Reliability:-
When it comes to reliability, TCP is trusted more than UDP, because TCP guarantees the delivery of the data with its ACK mechanism. If any segment does not reach the destination and the sender does not receive an ACK within a certain time, it resends the segment. On the other hand, UDP has no such ACK mechanism, so it does not guarantee data delivery. This means that UDP is a slightly unreliable transport protocol.
Ordering Mechanism:-
One of the key differences between TCP and UDP is the Order Mechanism. In TCP, sometimes due to network conditions, packets can be sent and received in a different order. To solve this problem, TCP assigns sequence numbers to each packet. At the receiver's end, these sequence numbers are checked thoroughly, and the packets are reordered in the correct order before delivering the data to the application. This process guarantees that the message is complete and meaningful, which is important for applications like file transfer or email.
On the other hand, UDP has no such reordering mechanism. It does not assign sequence numbers to packets, so if packets arrive out of order, they are passed to the application in the same order. This makes UDP faster but less reliable for applications where order matters the most. However, for real-time applications like video streaming, voice calls, or online gaming, the disorder of packets or slight loss of data is acceptable and does not significantly affect performance.
Error checking and correction:-
When we compare TCP and UDP for error checking and correction, TCP wins the race. TCP provides a robust error-checking mechanism. It uses sequence numbers, checksums, and acknowledgments to identify errors and retransmits missing or corrupted packets, ensuring complete and correct data delivery. On the other hand, UDP includes a simple checksum to detect errors, but it does not retransmit corrupted data automatically. If a packet is lost, the information is lost as well.
Congestion Control:-
TCP reconciles the data flow based on the capacity of the receiver and the capacity of the network to prevent network congestion and guarantee smooth data flow. TCP starts transmitting packets slowly at first (a process known as slow start) to avoid congesting the network, then gradually increases the speed until packet loss occurs or it reaches its limit. Once the limit is reached, TCP maintains the same speed to ensure stability. On the other hand, UDP does not have any built-in mechanism to control network congestion. If a UDP application needs to manage congestion, the application developer must implement their own strategies to control the data transmission rate. This can be achieved using algorithms like Token Bucket or Leaky Bucket.
Headers Size:-
The header size of TCP packets has a minimum size of 20 bytes and can increase up to a maximum size of 60 bytes, depending on the optional fields. TCP includes fields for sequence numbers, acknowledgment numbers, window size, and more to ensure reliable data delivery.
On the other hand, UDP has a fixed header size of 8 bytes. The UDP header contains only basic information, such as the source port, destination port, length, and checksum. This simplicity makes UDP faster and better suited for lightweight applications.
Applications/use Cases:-
TCP is mainly used where reliable data delivery is required, and ordered packets and error-free communication are essential. The applications where TCP is used include web browsing, emails, remote access, file transfer, and database communication, where reliable and complete packet delivery in the correct order is prioritised more than speed.
On the other hand, applications using UDP prioritise speed and efficiency over reliability. UDP also provides low-latency communication, which is critical for multiplayer games. Organisations like Netflix, YouTube, and Twitch use UDP to deliver smooth, real-time video streams.
The following port names are commonly used by TCP and UDP and are often asked in network engineering exams or interviews:
For TCP
FTP Data (Port 20)
FTP Control (Port 21)
SSH (Port 22)
Telnet (Port 23)
SMTP (Port 25)
TACACS (Port 49)
HTTP (Port 80)
POP3 (Port 110)
SFTP (Port 22) [over SSH]
HTTPS (Port 443)
For UDP
DHCP & BOOTP Server (Port 67)
BOOTP User (Port 68)
TFTP (Port 69)
NTP (Port 123)
SNMP (Port 161)
SNMP Trap (Port 162)
Syslog (Port 514)
ISAKMP (Port 500)
Conclusion:-
TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) both excel in their respective use cases. TCP is ideal for scenarios where reliable, error-free, and complete packet delivery is crucial, ensuring no loss of data. On the other hand, UDP is best suited for applications where speed and efficiency are prioritized, and slight packet loss does not significantly impact performance.