TCP vs UDP

Gokhan Kosem
3 min readJun 27, 2022

--

What is TCP?

TCP, or Transmission Control Protocol, is the most common networking protocol online. TCP is extremely reliable, and is used for everything from surfing the web (HTTP), sending emails (SMTP), and transferring files (FTP).

TCP is used in situations where it’s necessary that all data being sent by one device is received by another completely intact.

For example, when you visit a website, TCP is used to guarantee that everything from the text, images, and code needed to render the page arrives. Without TCP, images or text could be missing, or arrive in the incorrect order, breaking the page.

TCP is a connection-oriented protocol, meaning that it establishes a connection between two devices before transferring data, and maintains that connection throughout the transfer process.

To establish a connection between two devices, TCP uses a method called a three-way handshake: SYN, SYN-ACK, and ACK.

What is UDP?

UDP, or User Datagram Protocol, is another one of the major protocols that make up the internet protocol suite. UDP is less reliable than TCP, but is much simpler.

UDP is used for situations where some data loss is acceptable, like live video/audio, or where speed is a critical factor like online gaming.

While UDP is similar to TCP in that it’s used to send and receive data online, there are a couple of key differences.

First, UDP is a connectionless protocol, meaning that it does not establish a connection beforehand like TCP does with its three-way handshake.

Next, UDP doesn’t guarantee that all data is successfully transferred. With UDP, data is sent to any device that happens to be listening, but it doesn’t care if some of it is lost along the way. This is one of the reasons why UDP is also known as the “fire-and-forget” protocol.

A good way to think about these differences is that TCP is like a conversation between two people. Person A asks person B to talk. Person B says sure, that’s fine. Person A agrees and they both start speaking.

UDP is more like a protester outside with a megaphone. Everyone who is paying attention to the protester should hear most of what they’re saying. But there’s no guarantee that everyone in the area will hear what the protester is saying, or that they’re even listening.

Which is Faster — TCP or UDP?

In general, UDP is the faster protocol.

UDP is much simpler, and doesn’t try to establish a connection between devices before sending data, or verify that all the data even arrived. It simply sends out data to any device that requests it, and keeps doing that until the other device disconnects or there is no more data left to send.

But being faster doesn’t mean that UDP is the better protocol overall. It just means that it’s better in certain situations.

As mentioned earlier, TCP is necessary in situations where it’s vital that all data packets are sent in order, and that all packets arrive. The web just wouldn’t function without TCP.

And while TCP is slower because of the way it establishes connections, and due to the checks for missing packets, it can still be blazing fast. Because they’re on the web and use HTTP, sites like YouTube or Netflix all use TCP to send data to your devices.

TCP also allows for buffering, so your browser can request and load more data as you watch, allowing for smooth playback and for you to skip ahead to other parts of the video.

UDP is the better choice for live video and audio or online games where speed is more important than potential data loss.

When you make a call over Google Meet or Zoom, your video and audio are being transmitted over UDP. If some packets are lost along the way, it’ll just appear as a bit of lag or clipped video/audio.

--

--

Gokhan Kosem
Gokhan Kosem

No responses yet