If you’ve ever gone into technical mumbo-jumbo while using a VPN, you might have seen terms such as OpenVPN over TCP or OpenVPN over UDP. You might know that OpenVPN is the most secure VPN protocol. But what about TCP and UDP? What are these terms and what do they mean?
Let’s understand what TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are and when they can be used.
TCP and UDP: What’s Common?
TCP and UDP are network protocols that are used to send data packets. These data packets are just bits of data that travel over the internet. When you chat with your friend online, send an email, or send a page request through your browser, you send online data. This data is transferred in the form of tiny packets.
Both TCP and UDP forward the data packets from your device using ports to different routers until they reach the final destination. They are also used to send the packets to the IP address of the recipient. (An IP address is a special address that is assigned to each device connected to the internet.)
Both TCP and UDP work on top of the IP (Internet Protocol). This is why you might hear terms such as TCP/IP or UDP/IP. However, since TCP/IP and UDP/IP are used very often, they are referred to as just TCP and UDP.
While TCP and UDP are the most commonly used protocols, they aren’t the only ones used to transfer data packets. Another protocol that can be used is ICMP (Internet Control Message Protocol). However, since most connections rely on either TCP or UDP, we’ll focus on these two.
Let’s understand each of these protocols separately.
All About TCP
TCP is a more commonly used protocol than UDP.
When you open a web page on your browser, your device sends TCP packets to the server’s address. It’s a request to the server to send the data and information for the website. The web server replies by sending a course of TCP packets. These packets are stitched together by the browser to display a web page on your screen.
When you click on a link given on that page, or go to a different website, the browser again sends TCP packets to the server and the server responds by sending back more TCP data packets.
In essence, TCP isn’t a one-way communication. These packets are sent back and forth by your browser to the server and from the server to the browser.
The difference is that the browser sends request packets and the server responds by sending data packets that are stitched in the right way to form a fully-functional web page.
TCP numbers the packets so the recipient can get them in order. When the recipient gets a packet, it sends an acknowledgement to the sender. If the sender doesn’t get the acknowledgement, it will assume that the packet was not received so it will resend it.
TCP is serious about reliability. The packets are checked for errors to make sure the request is fulfilled correctly. TCP packets are tracked to make sure that no data is lost in between. Packets are also checked for corruption. This is why when you download files using TCP, they are received perfectly even if there are network issues in between.
However, if the other side is totally offline, eventually your system will give up trying and show you an error message that it could not setup the communication channel with the remote host.
All About UDP
As discussed earlier, UDP works similar to TCP in the sense that it transmits data packets. However, it doesn’t do any kind of error-checking. To make it lightweight and easy, UDP lets go of the reliability factor.
Putting packets in sequence, sending acknowledgements, and requesting resends takes a lot of time and it slows things down. UDP makes things fast by removing all the overhead steps.
With UDP, the sender sends the packets to the recipient. The sender doesn’t care if the recipient received them or not. It will continue sending the data packets. As a receiver, if you missed a couple of UDP packets in between, you can’t ask for them again.
Did you get all the packets? There’s no way to know. And you cannot get back any missing packets either. This sounds like a terrible deal but there’s a good thing about this communication – it’s faster than TCP.
As you may have guessed, UDP is not used in connections where reliability is a big concern. It’s used only when speeds are more important than a few lost packets. For example, if you want a network for online gaming, video conferencing, or broadcasts, UDP will be better than TCP.
UDP is Used for Gaming
If you miss a couple of UDP datagrams, you might feel that instead of walking, your character has suddenly teleported across the map. Or if you’re playing a first-person shooter, you’ve shot two bullets at once instead of one at a time.
The packets that were missed in between are already useless now. There’s no point in requesting them again. You’ll ignore this little glitch and continue playing as earlier. This is better than the alternative TCP, where your game would freeze.
In online gaming, what matters is what’s happening in real time. You aren’t concerned about the missed packets anyway. If you use TCP instead of UDP, there will be no small glitches but your game will be slow, which is a major annoyance.
TCP and UDP: What are the differences?
This graph sums up the differences, but we go into detail for each section below.
|Sequencing||TCP numbers each packet so they can be arranged in a sequence by the recipient||UDP sends the packets without numbering|
|Header size||Packets are heavy because of overheads||Lightweight packets with minimal headers|
|Error detection/correction||Error checking and error recovery||Error checking but no recovery. Corrupted packets are simply discarded and not requested again|
|Acknowledgement||Acknowledgement sent by the recipient||No acknowledgement is sent|
|Transfer method||Stream||Individual packets|
|Applications||File transfer, email, web browsing||Video conferencing, gaming, broadcasts|
Let’s get into the details.
As you now know, TCP and UDP both are used in online communications between the client and the server. Here are some primary differences between them.
TCP is connection-oriented and UDP is connectionless. This means that before sending TCP packets, a connection is established between the server and the client. This process of setting up a connection is called TCP handshaking. The stream of packets is then sent over this connection.
In UDP, there is no such connection. Each packet is sent individually and directly from the sender to the receiver without a reliable data channel.
TCP is a reliable protocol that adds a sequence number to the data packets as it sends out a stream. This helps the recipient arrange and stitch back the message together. UDP doesn’t add a number to its header, which means the recipient has no way of knowing if it received all the packets and in the right order.
Since UDP doesn’t have many requirements, it offers a faster connection. TCP, on the other hand, is slower but more reliable. If you need speed more than reliability, you should use UDP instead of TCP.
TCP has provisions for data packet sequencing, acknowledgements, error detection, and correction. This makes it a reliable protocol. On the other hand, UDP doesn’t have sequencing or acknowledgements. While UDP has error detection mechanism, it does nothing to correct the error. The erroneous packets are simply discarded.
5. Header size
Since TCP has more details (sequence of the packet, error detection, acknowledgement field etc.), the header of TCP packets is larger than that of UDP packets. This makes each packet heavy. This is why TCP connections are slower than UDP connections.
6. Error detection/correction
TCP has error detection and correction methods. When a packet is found to be corrupted, TCP doesn’t send an acknowledgement for it. This prompts the sender to resend the packet. This way, the complete message is delivered without errors.
In UDP, there is error detection via checksum but there is no error correction. If a given packet is found to be erroneous, it is simply discarded.
When TCP packets are received by the recipient, it sends back an acknowledgement to the sender. If the sender doesn’t receive the acknowledgement, it will assume that the packets were not delivered or were delivered corrupted. It will then proceed to resend the packets.
On the other hand, UDP doesn’t send an acknowledgement so the sender will not know if the packets were received or not.
8. Transfer method
TCP sends out a stream of data packets while UDP packets are sent individually. Data stream doesn’t have a defined boundary but individual packets possess proper boundaries.
9. Congestion control
TCP has provisions for congestion or flow control. Since TCP is connection-oriented, it ensures that there is no congestion on the data channel that’s been setup. UDP is connectionless and doesn’t care much about congestion. Each packet is sent separately and if a packet is lost due to congestion, the recipient can’t do much about it.
TCP is used in applications where reliability is more important, such as file transfer, emails, and web browsing. UDP is used in applications where speed is more important such as video conferencing, live streaming, and online gaming.
TCP ports vs UDP ports
When data travels on the internet to your computer, it is accepted on your system through TCP or UDP ports.
Your IP address is used to identify your computer on the internet. So your IP address is like the street address. All apartments on that street will share the street address. But each apartment has an apartment number as well. This apartment number is the port.
Your IP address has a number of ports. There can be 65,535 TCP and 65,535 UDP ports. When your browser sends or receives data on the internet, this data is sent from the online servers to your IP address and a specific port.
If the data is sent using TCP protocol, it will use one of your TCP ports and if it is transferred using UDP, it will connect using one of your UDP ports.
OpenVPN: TCP or UDP?
When you use OpenVPN, which protocol should you use it with? TCP or UDP?
OpenVPN is one of the many protocols you can use with a VPN. This article explains it and the other popular protocols.
When it comes to OpenVPN connections, both TCP and UDP perform well. Both offer excellent privacy and security when you use the VPN. To choose the right one, you must consider the application for which you want to use the VPN.
If you want a speedy connection and don’t mind losing a few packets, you should select UDP. And if reliability is your main concern, go for TCP. Keep in mind that both of them offer equal security from hackers and government surveillance.
It’s the application that decides the difference. If you want to use the VPN for gaming or live streaming, you can connect with OpenVPN with UDP. And if you want to download files, connect to a P2P network, or do regular browsing, you can connect using OpenVPN with TCP.
Don’t know what protocol to use? We give you a quick summary here.