If you’re using a
In this article, we will talk about the positives and the negatives in using TCP and UDP. Stay with me as we delve into a detailed analysis and comparison of TCP vs UDP.
TCP vs UDP: Understanding the basics
To find out which network protocol would suit you better, you first need to learn the basics. This brief explanation of TCP and UDP will help you understand the two protocols and find out which one aligns with your preferences:
- TCP: Stands for Transmission Control Protocol. It is a connection-oriented network protocol that relies on two-way communication between the sender and the recipient. TCP implements an error-correction technique; this means that if there are lost packets, they must be resent. Compared to UDP, TCP is more commonly used; it is suited in situations that require high reliability.
- UDP: Stands for User Datagram Protocol. UDP operates similarly to TCP, only without the error-checking process. In TCP, all of the back-and-forth data confirmations slow things down, and that’s what UDP is trying to avoid. When using UDP, the packets are just sent to the recipient on a one-way ride. The sender won’t wait to check if the recipient did receive the transmitted packets; the sender will just keep on sending new packets. This way, the device communicates and operates faster than with TCP. However, it comes at a cost—reduced reliability.
Finally got around to updating my testnet's event collector to use TCP. The previous one used UDP and worked a bit like so. pic.twitter.com/FVwnzUa34b
— MalwareTech (@MalwareTechBlog) February 1, 2019
The first thing you need to know here is that TCP is known for reliability whereas UDP is popular for speed. Both protocols share strengths and weaknesses, and we’ll look more into that in the succeeding sections.
This nerdy joke plainly explains how TCP and UDP work. TCP is eager to receive confirmation that the online destination did receive the packets. On the other hand, UDP just keeps on shoving them, along not caring whether the recipient got the packets or not. The fact that UDP doesn’t care whether or not the packets were received is what makes UDP much faster than TCP. We’ll talk more about that later.
TCP vs UDP: How they work
You read the basics of TCP vs UDP above, now let’s expand your knowledge a bit further:
- How TCP works: When a user opens a web page on their browser, their device sends TCP packets to the address of the recipient server. It is practically a request to send data and information about the destination website. The receiving web server replies by sending TCP packets. The user’s browser then stitches the packets together and displays the web page. To establish a connection, TCP uses a three-way handshake.
- How UDP works: As I said, UDP works like TCP, except that UDP doesn’t require confirmation. It lets go of the reliability factor by omitting error-checking. UDP uses a simpler transmission model—it doesn’t perform the handshaking process of TCP which lessens reliability. In other words, with UDP, the sender sends packets to the recipient, but the sender won’t care if the recipient received them or not. The sending device will just keep on sending the packets.
Both TCP and UDP send packets over the Internet on top of the IP (Internet Protocol). Whether you’re sending packets via TCP or UDP, the packets are sent to an IP address.
The video above shares a more detailed analysis of how TCP and UDP work. Basically, the difference between the protocols’ operation is that while TCP makes sure that the recipient has received the packets, UDP just continues to send the next packets. If a few packets get lost along the way, UDP won’t require the sender to resend them; the packets will be considered lost.
TCP also uses a three-way handshake to establish a connection:
- The client sends a SYN to the server.
- The server responds with a SYN-ACK.
- Lastly, the client sends an ACK back to the server.
Below is a visual representation of the three-way handshake process and how it is used in practice.
— IPCisco (@ip_cisco) February 27, 2018
When the three-way handshake process is completed, both the client and the server have received an acknowledgment of the existing connection.
TCP: Pros and Cons
Now that you know how TCP and UDP work, let’s start with the pros and cons of using TCP:
- Reliable and secure: TCP guarantees that the connection is uncorrupted and that the data packets are secure. TCP controls the flow of the connection and detects potential errors.
- Connection-oriented: With TCP, data travels both ways. This means the connection must be established first for users to reach their desired online destination.
- TCP is slower than UDP: TCP has a more complex connection—the header of the TCP packets is larger than that of UDP packets. That’s why TCP connections are considerably slower than UDP connections.
TCP vs UDP explained in pictures 🙂 pic.twitter.com/YSeXyRBOng
— Ruben Spruijt (@rspruijt) January 9, 2019
TCP brings reliability and security while sacrificing speed. That’s the reality—you can’t have it both ways. Your connection will either be secured but slow, or unsecured but fast. You just have to figure out whether speed or security is more important to you.
UDP: Pros and Cons
The obvious perk to UDP is speed. Besides that, UDP is known for:
- One-way connection: With UDP, you won’t need to wait for a connection to be established. Data flows only in one direction. This comes in handy when you want to watch live streams.
- UDP is fast: Compared to TCP, UDP is faster as it doesn’t have many requirements.
- No error correction: While UDP does have an error-detection method, it doesn’t perform error-correction. While the absence of the error-correction method speeds up the connection, it also makes UDP unreliable.
As you can see, UDP sacrifices the error-correction process to make connections faster.
TCP vs UDP: When to use them
TCP and UDP have different strengths and weaknesses, so both will perform differently under certain circumstances:
- When to use TCP: TCP is suited for applications that require high reliability, without relying on fast connectivity. With TCP, the transferred data is guaranteed to remain intact and will arrive in the same order as it was sent. TCP is great for viewing websites, emails, or other network communication where zero packet loss is a requirement and the data must be error-free. For instance, if you want to use a
VPNfor downloading files via a P2P network, you must use TCP with your VPN.
- When to use UDP: UDP is more suitable for apps that need a fast, efficient transmission. UDP makes data streams run faster because its overhead is lesser than that of TCP. In gaming, streaming, and other real-time applications (where late or retransmitted data is useless), UDP is king.
For example, in online games, if you miss some packets, the player character teleports across the map as you receive the new packets. It won’t really matter if you request the old packets that you missed; the game will still continue. In this case, UDP clearly has the upper hand; all that matters is what is currently happening when you’re playing the game, not what happened a few seconds ago.
UDP is always faster.
Messages blasting out and arriving out-of-order,
That's why it's used for multiplayer gaming.
TCP is far too slow due to the handshaking and guaranteed message ordering for the recipient
— Phil Wilson (@_Phil_Wilson_) December 7, 2018
The same analogy can be used for live streaming. If you’re watching an NBA game online, and the stream glitches and misses a few packets, would you like your screen to freeze while it waits for the other packets to be re-sent? Or would you like to watch the rest of the game as it happens in real-time?
TCP vs UDP: Which one to use with your
When you install your
- Personal preference: Know that both TCP and UDP will perform well with OpenVPN. Both protocols offer excellent privacy and security, and choosing the right one is a matter of personal preference.
- Speed vs reliability: If you want a speedier connection and don’t mind losing a few packets, go with UDP. If reliability is your main concern, go with TCP. Keep in mind that both protocols offer equal protection against hackers and other malicious attacks.
Even though TCP is deemed more secure, if you want both speed and security, I recommend choosing a good
[affilioProvider max=”3″ top=”n” cat=’home’]