A datagram is a self-contained, independent unit of data that carries enough addressing information to be routed from source to destination without a prior connection between the endpoints. Among transport protocols in networking, the datagram is the basic unit of connectionless delivery, most familiar as the UDP datagram that travels inside an IP packet.
Datagram service is deliberately minimal: the network makes a best-effort attempt to deliver each message, but it promises nothing about arrival, order or duplication. Applications that need those guarantees must add them themselves or choose a connection-oriented protocol such as TCP.
How datagram delivery works
Each datagram is handled independently by every router along the path. The router reads the destination address, consults its forwarding table and sends the datagram onward, keeping no per-flow state about earlier or later messages from the same sender.
Because there is no setup phase, the first byte of application data can leave the sender immediately. Two datagrams sent back to back may take different routes, arrive in reverse order, arrive twice or not arrive at all, and the network layer will not report any of these outcomes to the sender.
This design follows the end-to-end principle: keep the network core simple and place reliability in the hosts that actually need it. It is also why the Internet scaled so well, since routers never track millions of conversations.
At the receiving host, the operating system matches each arriving datagram to a socket by its destination port and address, then places it in that socket’s receive buffer. If the buffer is full or no application listens on the port, the datagram is dropped; in the second case the host may return an ICMP port unreachable message, which is often the only signal a sender ever gets.
Checksums offer limited protection. The 16-bit checksum detects most accidental corruption, but it cannot detect every error pattern and offers no security against tampering, so applications that need integrity use cryptographic protocols such as DTLS or QUIC on top.
Structure of a UDP datagram
The UDP datagram, defined in RFC 768, has one of the smallest transport headers in common use: 8 bytes in four fields. Everything else is payload handed directly to the application through a socket bound to the destination port number.
The table below lists the header fields and their roles.
| Field | Size | Function |
|---|---|---|
| Source port | 16 bits | Identifies the sending socket; optional and may be zero |
| Destination port | 16 bits | Selects the receiving application socket |
| Length | 16 bits | Header plus payload, minimum 8 bytes |
| Checksum | 16 bits | Detects corruption; mandatory over IPv6 |
The length field allows up to 65,535 bytes, but in practice a datagram should fit within the path MTU. On standard Ethernet that leaves about 1,472 bytes of payload over IPv4 and 1,452 bytes over IPv6 before fragmentation is required.
Datagram compared with segment, packet and frame
Networking uses several names for a protocol data unit, and the correct one depends on the layer. A datagram usually refers to a connectionless unit at the transport or network layer, while TCP data is called a segment because it belongs to an ordered byte stream.
| Name | Typical layer | Connection model |
|---|---|---|
| Frame | Data link, such as Ethernet | Local delivery on one link |
| Packet or IP datagram | Network layer | Connectionless, routed hop by hop |
| Datagram | Transport layer with UDP | Connectionless, message oriented |
| Segment | Transport layer with TCP | Connection oriented byte stream |
A second important difference is message boundaries. A datagram arrives either whole or not at all, so one send call matches one receive call. TCP, by contrast, may merge or split writes, which forces applications to add their own framing.
Where datagram transport is the right choice
Datagram transport fits workloads where low latency matters more than perfect delivery, or where the application already implements its own recovery. It is also the only practical option for broadcast and multicast, since a connection cannot be negotiated with an unknown group of receivers.
The following decision table connects common use cases to the reason datagrams suit them.
| Use case | Why datagrams fit | Typical protocol |
|---|---|---|
| DNS queries | One short request and reply, no setup cost | DNS over UDP port 53 |
| Voice and video calls | Late data is useless, retransmission adds delay | RTP over UDP |
| Online games | Fresh state replaces lost updates | Custom UDP protocols |
| Modern web transport | Reliability built in user space | QUIC over UDP |
| Network discovery | Broadcast or multicast to unknown hosts | DHCP, mDNS, SSDP |
QUIC illustrates a modern pattern: it uses UDP datagrams as a thin carrier and rebuilds reliability, ordering and congestion control above them, avoiding head-of-line blocking across independent streams.
Limitations and common mistakes
The freedom of datagram transport shifts responsibility to the developer. Because UDP has no built-in congestion control, a careless sender can flood a link and harm other traffic, so guidelines in RFC 8085 ask applications to pace their transmissions.
The table below lists frequent problems, their causes and practical fixes.
| Symptom | Likely cause | Remedy |
|---|---|---|
| Large messages vanish | IP fragmentation and lost fragments | Keep datagrams under the path MTU |
| Out-of-order data | Independent routing of each datagram | Add sequence numbers in the application |
| Silent loss under load | Full socket receive buffers | Increase buffers and add acknowledgments |
| Traffic blocked by middleboxes | Firewalls and NAT timeouts for UDP | Send keepalives and allow fallback |
| Amplification abuse | Spoofed sources with large replies | Validate clients and limit response size |
A frequent misconception is that datagrams are inherently unreliable. On a healthy network most arrive intact; the point is simply that delivery is not guaranteed, and robust applications must be designed for the cases where it fails.
The idea in brief
A datagram is like a postcard sent through the mail. Each card carries its own address and travels on its own. There is no phone call first to check that someone is home.
Most postcards arrive, but a few may be late, arrive out of order or get lost. Nobody tells you when that happens. This makes datagrams fast and simple, and the sender must decide whether lost cards matter.
A practical scenario
A company runs an internal video conferencing service for 400 remote employees. Early tests over TCP showed frozen frames and growing delay whenever Wi-Fi links dropped a few packets, because TCP paused the stream to retransmit data that was already too old to display.
The engineering team moved media to RTP over UDP datagrams, sizing each one at about 1,200 bytes to stay safely below typical path MTUs. The codec conceals the occasional missing datagram, and a lightweight feedback channel lowers the bitrate when receivers report loss above about 2 percent.
After the change, calls tolerated brief packet loss with only minor visual artifacts, and end-to-end delay stayed under 150 milliseconds on most connections, which kept conversations natural.