codingstuff.io
ExploreTutorialsProblemsCS Subjects
Get Started
ExploreTutorialsProblemsCS Subjects
Get Started
codingstuff.io

Master the art of building software through interactive tutorials, real-world problems, and guided projects.

Pune, Maharashtra, India

codingstuffmail@gmail.com

Product

  • Explore
  • Tutorials
  • Problems
  • CS Subjects

Company

  • About
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Sitemap

© 2026 codingstuff.io. All rights reserved.

Built with ❤️ for developers everywhere

/
/
All Subjects
🌐

Computer Networks

26 chapters

1Network Topologies & LAN/WAN2Network Devices (Hub, Switch, Router)3OSI Reference Model4OSI Model & TCP/IP Suite5TCP/IP Protocol Suite6Switching Techniques (Circuit, Packet)7Data Link: Framing & Error Detection8Error Correction (Hamming Code)9Flow Control (Stop-and-Wait, Sliding Window)10MAC: CSMA/CD & CSMA/CA11Network Layer & Routing12IP Addressing (IPv4, IPv6)13Subnetting & CIDR14Routing Algorithms (Distance Vector, Link State)15ARP, ICMP, and NAT16DHCP Protocol17Transport Layer Services18Transport Layer: UDP19Transport Layer: TCP & 3-Way Handshake20TCP Congestion Control21Application Layer: DNS & HTTP22Application Layer: SMTP & FTP23Socket Programming Basics24Wireless Networks & Wi-Fi Standards25VLANs & Spanning Tree Protocol26Network Security & Cryptography
SubjectsComputer Networks

Transport Layer: UDP

Updated 2026-05-01
3 min read

Transport Layer: UDP

The Transport Layer (Layer 4) is responsible for process-to-process delivery. While the Network Layer (IP) gets the packet to the correct destination computer, the Transport Layer ensures the data gets to the correct application program on that computer using Port Numbers.

There are two primary protocols at the transport layer: TCP (reliable) and UDP (unreliable).

1. What is UDP?

User Datagram Protocol (UDP) is a connectionless, unreliable transport protocol. It provides the absolute bare minimum functionality required to deliver a payload from an application on one machine to an application on another.

  • Connectionless: UDP does not establish a connection before sending data. It does not perform a handshake. It simply grabs the data and fires it out of the network port.
  • Unreliable: UDP provides zero guarantees that the data will actually arrive.
  • Unordered: If you send Packet 1, Packet 2, and Packet 3, they might arrive at the destination as Packet 3, Packet 1, Packet 2. UDP does not care and will not reorder them.
  • No Congestion Control: If the network is heavily congested, TCP will politely slow down to avoid making the problem worse. UDP will blindly continue blasting packets at full speed, potentially causing network collapse.

2. The UDP Header

Because it provides virtually no features, the UDP header is incredibly small and simple. It consists of exactly 8 bytes (compared to TCP's 20-60 bytes).

The header contains only 4 fields (2 bytes each):

  1. Source Port: The port number of the application sending the data.
  2. Destination Port: The port number of the application receiving the data.
  3. Length: The total length of the UDP header and the payload data.
  4. Checksum: Used for basic error detection. If the payload gets corrupted by electrical interference during transit, the receiving OS will calculate a mismatched checksum and silently drop the packet.

3. Why use an Unreliable Protocol?

If UDP is unreliable and loses data, why would anyone ever use it?

Because it lacks the massive overhead of handshakes, sequence numbers, and acknowledgments, UDP is blazing fast. It is used in scenarios where high-speed delivery is vastly more important than perfect accuracy.

Common UDP Use Cases:

  1. Live Video/Audio Streaming (VoIP, Zoom, Skype): If you are on a live voice call and a packet containing 10 milliseconds of audio is lost over the Atlantic Ocean, you do not want the system to pause the call, request a retransmission, and play that audio 3 seconds late. You just want to skip the lost audio (a tiny glitch in the sound) and continue with real-time delivery.
  2. Online Multiplayer Gaming (FPS games): If a packet containing your character's coordinates is dropped, the server shouldn't waste time asking for a retransmission of where you were 500 milliseconds ago. It only cares about where you are right now in the next incoming packet.
  3. DNS Queries: When you type google.com, your browser needs to quickly ask a DNS server for the IP address. This is a tiny, single-packet request. Setting up a heavy, 3-way TCP handshake just to ask one quick question is horribly inefficient. UDP is used instead. If the request is lost, the browser just asks again a second later.


PreviousTransport Layer ServicesNextTransport Layer: TCP & 3-Way Handshake

Recommended Gear

Transport Layer ServicesTransport Layer: TCP & 3-Way Handshake