UDP vs TCP

To understand the differences between TCP and UDP, you must first have a basic understanding of the underlying IP protocol. This article will explain what all these protocols are, the difference between UDP and TCP, and some examples of how each is used.

IP protocol

tcp udp ip protocols

Every device that’s connected to the internet is assigned a unique IP address made up of numbers and decimals. Like physical street addresses, IP addresses enable computers connected the internet to find each other and send stuff back and forth, a function called “routing.” Without the IP protocol, we wouldn’t have the internet.

The internet protocol works by splitting data into little chunks called datagrams or packets. The chunks are then sent across the internet from one IP address to another.

In addition to the data itself, IP packets contain routing information like the destination IP address of where they’re headed. This information is called the “header.”

Once a packet leaves your device, it goes to a gateway. This gateway is another computer that can see a portion of IP addresses on the internet. If the packet’s destination IP address is not one that the gateway can see, the packet is forwarded to the next gateway up the line. This process repeats until the packet reaches a gateway that recognizes the destination IP address as belonging to its domain. That gateway forwards the packet to the computer whose address is specified in the header.

Because the data is split up into packets, it doesn’t all have to travel the same route over the internet, or even arrive in order.

Every time you use the internet, chances are you’re using the IP protocol. It’s agnostic of the type of data being exchanged, so it’s used for pretty much everything, including text, images, audio, video, gaming, email, messaging, files, and more.

Most applications today use the fourth version of the internet protocol, known as IPv4. You might have also heard about IPv4’s replacement, IPv6. Currently, the two versions work in parallel, but adoption of IPv6 is growing and will ultimately replace IPv4 altogether. The reason is that the world is running out of IPv4 addresses—its inventors didn’t foresee the proliferation of the internet to the extent that it exists today. IPv6 allows for far more IP addresses plus some other technical upgrades that we won’t delve into here.

See also: IPV6 vs IPV4

TCP

TCP came before UDP. It stands for Transmission Control Protocol. You’ll often see it referred to as TCP/IP, though there’s no distinction between that and TCP.

The IP protocol breaks up data into packets and sends them to a destination over the internet, but how do you put those packets back together once they arrive? That’s what TCP was invented for. Once packets reach their destination, they are reassembled by the receiving device back into their original form.

TCP requires both parties to communicate in order to establish a connection and send data. TCP guarantees the recipient will receive packets in order according to sequence numbers included in the header. The recipient will send a message back to the sender for each packet, acknowledging that they’ve been received. Any packets not acknowledged by the recipient are sent again. Packets are checked for errors using a checksum, which is also included in the header.

TCP_header

Because of all this back-and-forth between client and server, TCP can reliably ensure the integrity of data exchanged over the internet. Put simply, it can guarantee the data arrives exactly as it was sent with no modifications or missing parts. This makes TCP useful for a huge range of applications, and it’s the most commonly used protocol on the internet. Any time you click a link, download a file in your web browser, update an application, or open an email, TCP is probably used.

However, all that back-and-forth communication slows TCP down. If a packet goes missing, the entire operation is held up until it’s sent again. While this only translates to milliseconds in real life, it can impact performance for applications that require a lot of bandwidth. Enter UDP.

UDP

UDP stands for User Datagram Protocol. Recall that a datagram and a packet are more or less the same thing. UDP, also built on top of the IP protocol, works similarly to TCP, but is simpler and faster.

The main difference is that UDP doesn’t require the recipient to acknowledge that each packet has been received. Any packets that get lost in transit are not resent. This enables computers to communicate more quickly, but the data received might not exactly match the data sent.

UDP packets don’t have sequence numbers, so they can arrive out of order. They do have checksums, though, so the packets that do arrive are protected against corruption or modification in transit.

UDP_header

For this reason, UDP is used when speed is preferred over integrity and error correction. Some common applications include streaming video and music, live broadcasts, voice and video calling (VoIP), and online gaming. In these scenarios, it doesn’t really matter if you lose the occasional video frame or button press, which favors UDP. DNS traffic is usually exchanged over the UDP protocol.

See also: Guide to UDP

OpenVPN over UDP and TCP

Many popular VPN apps that rely on the OpenVPN protocol allow users to choose between the UDP and TCP protocol. Neither is particularly better than the other and most end users won’t notice much of a difference. As we’ve mentioned before, UDP will generally offer better speeds, but it varies on a case-by-case basis.

In some instances, one or the other might be required to bypass a firewall. UDP and TCP can operate on different ports, and some firewalls might blacklist OpenVPN’s usual UDP port, for example. If you find that your OpenVPN connection is being blocked due to censorship, try switching to the other protocol. TCP is generally better for this.

UDP vs TCP

Here’s a wrap-up of some of the major differences between UDP and TCP:

UDP:

  • Used for streaming video, gaming, VoIP, live broadcasts
  • Faster and requires fewer resources
  • Packets do not necessarily arrive in order
  • Allows missing packets; sender cannot know whether a packet has been received

TCP:

  • Most widely used protocol on the internet
  • TCP guarantees no packets are missing and all data sent makes it to the recipient
  • TCP sends packets in order so they can be easily stitched back together
  • Slower and requires more resources

If you understand the following joke, then you have a basic grasp of the differences between TCP and UDP.

tcp udp joke

Breitling Wingwalkers” by Agnn Foon licensed under CC BY 2.0

Internet layering” by Jsoon eu licensed under CC BY-SA 3.0