The Difference Between TCP And UDP
Does understanding the difference between TCP and UDP have you running around in circles? Take a few minutes to read through our article about these two data protocols and find out when and why data is sent by one and not the other.
The other day I was watching Netflix and had a few moments of lag during the video stream. It wasn’t a catastrophic incident, but it got me wondering why Netflix chooses to use TCP rather than UDP when the latter was undoubtedly faster. It’s the protocol I use for gaming, after all. So I was determined to find out the difference between TCP and UDP to answer my question.
What Is the Difference Between TCP and UDP?
TCP stands for Transmission Control Protocol. UDP is the acronym for User Datagram Protocol. Both UDP and TCP are protocols that are used for sending data over the internet bundled in packets. They do this by forwarding the data from your computer then to an intermediary router which is finally sent to its destination. UDP is a faster process than TCP because it has fewer verification processes. UDP sends the data packets individually while TCP sends out data packets in streams.
What is TCP?
Image via: Pixabay
So here’s how the process works using TCP. When you load a webpage, your computer sends the TCP packets to the web server’s address requesting the webpage. The web server returns with a stream of TCP packets. Your web browser organizes these packets to form the web page you are loading and display it.
Your web browser sends TCP information bundles to the server, and then the server sends the TCP packets back. This back and forth communication is the process whether you are clicking on a link, chatting with a friend, signing in to a website, or posting a comment. TCP is the most commonly used protocol.
TCP has four layers. Each of these adds addresses whether it is the physical, logical, port, or application-specific address. They are:
- Link layers
- Network layers
- Transport layers
- Application layers
TCP requests confirmation that the recipient has received the packet which is also checked for errors. TCP packets are tracked. Tracking keeps the data from being corrupted or lost.
TCP is connection-oriented. Being connection-oriented means the devices that communicate with each other should make a connection before transmission and close the connection after transfer. This process is called TCP handshaking.
TCP is a more reliable data transfer protocol because it makes sure that the data is not out of order, duplicated, or missing. It does this through a mechanism called PAR (Positive Acknowledgement with Retransmission).
It is also able to manage the transmissions to reduce congestion in the transference with a flow control mechanism. Each time a packet is received, there is a message sent. This message confirms the current capacity of the receive window so that the application knows when to send more packets.
The header size for TCP is 20 bytes because it has more details. Both UDP and TCP headers have a 16-bit destination and source port fields which is used to reply to the message.
What Is UDP?
Image via: Flickr
On the other hand, UDP is connectionless. UDP works similarly to TCP, but there are no error-checking nor confirmation processes. UDP is a faster data transference and is often used for things like online games and live broadcasts.
It is not as reliable as TCP since the data transfer is not acknowledged, nor is there any retransmission of lost data. There is no data sequencing, either. If the app requires order, it must be managed by the application layer.
The header size for UDP is 8 bytes. UDP does have an error detection process via checksum; however, it does not correct the error. It merely discards the corrupted packets.
Who Decides Whether To Use UDP or TCP?
Image via: Pixabay
The developer decides whether the application or program uses UDP or TCP. If speed is essential, more than likely the app will use UDP. If reliability and confirmation are necessary, the app will probably use TCP.
You don’t need to know which protocol each app uses to configure a firewall, VPN, or router. Choose the “both” option and the privacy rules will be applied to TCP and UDP traffic.
Typically, TCP is used by:
- World Wide Web (HTTPS, HTTP)
- Email (SMTP, POP3, IMAP4)
- File Transfer Protocol (FTP)
- Secure Shell (SSH)
So when you are transferring a file, sending an email or doing some web browsing, you most likely using TCP because they need guaranteed message delivery.
UDP is often used by:
- Dynamic Host Configuration Protocol (DHCP)
- Domain Name System (DNS)
- Routing Information Protocol (RIP)
- Voice over Internet Protocol (VoIP)
- Simple Network Management Protocol (SNMP)
- Trivial File Transfer Protocol (TFTP)
Therefore if you are gaming, watching a live broadcast or participating in video conferencing, it’s probably a UDP that is sending the packets. UDP use is predicted to increase with IoT in the future.
When these data packets travel from the internet to your computer, they are accepted through UDP or TCP ports. Your IP address identifies your computer to the internet and has several ports. If the data has been sent via TCP, it will be received on your computer at a TCP port. If the information was transferred through UDP, it would be routed to a UDP port.
Why Do Video Streaming Applications Use TCP Rather Than UDP?
Image via: Pixabay
Video streaming applications like NetFlix or YouTube are not sending live data; thus speed is not necessarily as important. The apps receive chunks of information and store it and in the event of a short connection failure, still, have information to broadcast so that the streaming appears seamless. If the application were sent using UDP, those stoppages would result in dropped packets and sections of the video would be lost.
It isn’t possible to store information in a live broadcast, whether it is an online game or video call. With online gaming, those lost packets are not as important as the real-time interaction between players. For that reason, gaming uses UDP, and those dropped packets result in “teleporting” instances, which doesn’t hinder the live play.
So understanding the difference between TCP and UDP and how each process the information transfer makes it clear why video streaming uses TCP and video calling uses UDP.