DEV Community

Cover image for UDP in Depth
Tamerlan Gudabayev
Tamerlan Gudabayev

Posted on

UDP in Depth

Two weeks ago I published an article about TCP.

Having a single article, about TCP isn't nice.

So here's another one this time about UDP.

Today you will learn:

  • How does the UDP protocol work
  • The packet format that UDP protocol uses
  • Applications behind the UDP protocol

What is the UDP Protocol?

Alt Text

UDP which stands for User Datagram Protocol is one of the main protocols of the internet protocol suites.

But some of you may ask?

"What is a protocol?"

A protocol is essentially a set of rules that allows two computers to talk to each other.

There can be many different sets of rules, hence we have many different protocols.

UDP is one of them.

But what makes UDP different?

Short Answer: UDP is stateless, meaning it doesn't save any state between the client and server, it also is very light making it fast, but the downside is that it's not reliable, packets can go missing, corrupted, etc...

Long Answer: Read on...

UDP Packet Format

Alt Text

In our last article about TCP, we found out that TCP has a ton of headers.

Unlike TCP, UDP is light, hence having the minimal amount of headers.

Let's quickly go over each field:

  • Source Port — The sending device port.
  • Destination Port — The receiving device port.
  • Length — This field specifies the length in bytes of the UDP header and UDP data.
  • Checksum — Indicates whether the header was damaged in transit.
  • Data — The actual info that your sending

UDP Features

Alt Text

To be honest, there isn't much to say so let's condense the features of UDP in a list:

  • UDP does not acknowledge packets, so if data goes missing, it won't be retransmissioned.
  • UDP is a good protocol for data flowing in one direction
  • UDP is simple and suitable for query-based communications.
  • UDP is stateless, so it basically doesn't save any state between the client and server.
  • UDP does not provide congestion control, meaning that it doesn't regulate the amount of data is being sent over.
  • UDP does not guarantee the orderliness of data

It sounds like I'm talking about the cons of UDP, but there are in fact many use cases for it. For one it's simple and two it's fast.

UDP Applications

Alt Text

  • Streaming Media — Streaming sites are fine with loss packets, if one frame is lost in a video it won't affect the quality much, but what's important is speed. This is why UDP is a good protocol for streaming media.
  • Domain Name Servers — This is used to get the IP address from domains for example leads to This works well using UDP because queries must be fast and only consist of a single request followed by a single reply packet.
  • VPN - Some VPN systems such as OpenVPN may use UDP and perform error checking at the application level while implementing reliable connections.


Congratulations, you are one step closer in being a better developer!

This was a pretty short post, there isn't much to say (surface-level) about UDP, but either way I hope you enjoyed today's article.

If you enjoy my content, I have more in my personal blog, you can check it out here.

Also, I tweet snippets of useful stuff over twitter @tamerlan_dev

Thanks For Reading!!

Top comments (3)

alafasy profile image

Very nice article, I enjoyed reading your post, very nice share . Iplwin online cricket betting

Some comments may only be visible to logged-in visitors. Sign in to view all comments.