TCP and UDP are two protocols of the transport layer of the TCP/IP Model. Both are used for data transmission. You may have also heard their names when configuring firewall software, setting up a router, etc. But, what are the dissimilarities that make them different?
To understand the difference between TCP and UDP, first we have to see what they are.
What is TCP?
TCP stands for Transmission Control Protocol.
TCP is a connection-oriented transport communication protocol that guarantees the establishment of a connection between the sender and receiver before data transmission. It sends the data packets as a stream of bytes in an ordered manner. For instance, it is similar to a telephone system that requires a full connection between both ends before they can start talking to each other.
The Three-way Handshaking is being used for establishing the TCP connection. Three-way Handshaking is a process of establishing and acknowledging a connection. The process of data transfer begins after the establishment of a connection. TCP takes messages from a sender and divides them into segments/ data packets and transmits to the receiver. Each segment contains a header and data. The size of the header is 20 bytes. Until the completion of the exchange of messages, TCP ensures that a connection is maintained.
TCP ensures the order of data sent to the receiver. This will help to reorder the data packets if they arrived in the wrong order. Above all, TCP is more reliable. TCP has error detection and correction methods. After receiving the message, the recipient must message back to the sender for each packet, acknowledging what they received. If the sender doesn’t get a correct response then, it will resend the packets to ensure that the receiver received them. However, all the back-and-forth communication slows down the speed of data transmission. In addition, it also provides flow control to verify that a sender is not sending too many packets to the receiver at once.
What is UDP?
UDP stands for User Datagram Protocol.
The UDP is a connectionless transport protocol with very low overhead. Unlike, TCP UDP neither establishes a connection between the sender and receiver nor checks whether the receiver is ready to receive data or not. Due to this, UDP has fast transmission capabilities but no guarantee for message delivery. For example, traditional mail delivery is the same as UDP, as there is no acknowledgment for receiving a letter.
In UDP, a datagram is a unit for data transfer. In other words, the datagram is similar to the data packet. UDP is connectionless, so three-way handshaking is not required. It just uses a simple transmission model. Each segment contains an 8-byte header and variable-length data. UDP doesn’t ensure the sequence of data transmitted.
UDP only uses checksum for error detection. When the receiver detects an error through the checksum, the user datagram is simply discarded. The sender will not retransmit the data due to the absence of the concept of acknowledgment. It also does not provide flow control and may send abundant data to the receiver at once. This makes UDP less reliable. Although, it can be used when speed is preferred over coherence and error correction.
Comparison between TCP and UDP
Features | TCP | UDP |
Full-Form | Transmission Control Protocol | User Datagram Protocol |
Functionality | Always establish a connection between sender and receiver before data transmission | Sends data directly to the receiver without establishing any connection |
Reliability | More reliable than UDP | Less reliable than TCP |
Connection Type | Connection-oriented | Connectionless |
Speed of Transmission | Slower than UDP | Faster than TCP |
Header Size | 20 bytes | 8 bytes |
Sequence of data packets | Transmission of data packets in a particular order | No sequencing |
Retransmission of Data | Possible, in case of data loss | No retransmission |
Acknowledgement | It acknowledges the reception of data packets | Never provides acknowledgment |
Overheads | Lower but greater than UDP | Very low |
Broadcasting | Doesn’t support | Supports broadcasting and multicasting |
Flow Control of Data | It provides flow-control | No flow control mechanism |
Error detection and correction | It has error detection and correction mechanism | It only provides error checking via checksum |
Handshake | Uses SYN, SYN-ACK, ACK in the three-way handshaking | No handshake |
Weight | It is a heavy-weight protocol | It is a lightweight protocol as there is no ordering of messages, no acknowledgment, etc. |
Used By | HTTP, SMTP, FTP, etc | DNS, SNMP, DHCP, etc |
Applications | File transfer, Emails, Web Browsing | Video Conferencing, Online gaming, Live Streaming |