What Is a Datagram? Definition and How It Works

A datagram is a small, self-contained unit of data sent across a network. It carries everything needed to reach its destination, including the sender’s address, the recipient’s address, and error-checking information, without relying on any prior connection between the two. Think of it like mailing a letter: you write the address on the envelope, drop it in the mailbox, and the postal system routes it on a best-effort basis. There’s no guarantee it arrives, no notification if it’s lost, and no promise that letters mailed in order will show up in order.

How Datagrams Work

When a device needs to send data across the internet, it breaks the message into small pieces called datagrams (also called IP packets). Each one gets stamped with the same destination address but is sent independently. Routers along the way examine each datagram and forward it toward the destination, but different datagrams from the same message can take completely different paths through the network. They may experience different delays, arrive out of order, or not arrive at all.

It’s the receiving device’s job to collect all the datagrams, figure out the correct order using information embedded in each one, and reassemble them into the original message. This process is the core of what’s called packet switching, which is how virtually all internet communication works.

Connectionless Delivery

The defining trait of a datagram is that it’s connectionless. The sender doesn’t establish a relationship with the receiver before transmitting. There’s no handshake, no confirmation that the other side is ready, and no acknowledgment that the data arrived. The network simply makes its best effort to deliver each datagram independently.

This has a major practical advantage: you don’t need to know anything about the recipient ahead of time. It also makes broadcasting possible. When a device sends data to many recipients at once, it can’t maintain a separate connection with each one. Datagrams solve this by treating each packet as a standalone delivery.

The tradeoff is reliability. If a datagram gets lost or corrupted in transit, the network won’t automatically resend it. Higher-level protocols like TCP can add reliability on top of datagrams by tracking what arrived and requesting retransmissions, but the datagram layer itself makes no such promises.

What’s Inside a Datagram

An IPv4 datagram has a header section and a data section. The header contains the metadata routers need to forward the packet correctly. Key fields include:

  • Source and destination addresses: the IP addresses of the sender and receiver.
  • Time to Live (TTL): a counter that starts at up to 255 and decreases by one at every router. If it hits zero, the router discards the packet. This prevents datagrams from looping endlessly through the network if there’s a routing error.
  • Protocol: tells the receiving device which protocol is inside the datagram’s payload, such as TCP (value 6), UDP (value 17), or ICMP (value 1, used for tools like ping).
  • Header checksum: an error-detection value that lets each router verify the header hasn’t been corrupted. Because the TTL changes at every hop, routers recalculate this checksum each time they forward the packet.
  • Identification, flags, and fragment offset: fields used to handle fragmentation when a datagram is too large for a network link.

The minimum IPv4 header is 20 bytes. The data section carries whatever payload the sending application produced.

Fragmentation: When Datagrams Are Too Large

Every network link has a maximum transmission unit (MTU), which is the largest packet size it can carry in one piece. A typical Ethernet link has an MTU of 1,500 bytes. If a datagram exceeds the MTU of a link it needs to cross, it gets split into smaller fragments. Each fragment travels independently and gets its own IP header (adding 20 bytes of overhead per fragment). The destination device reassembles the fragments into the original datagram before passing the data up to the application.

Reassembly isn’t trivial. Fragments can arrive out of order or get lost entirely. The receiving device has to allocate memory for the full datagram before all pieces arrive, and it typically waits up to 60 seconds for missing fragments before giving up. Because of this overhead and complexity, modern networks generally try to avoid fragmentation by discovering the smallest MTU along a path and sizing packets accordingly.

Datagram vs. Packet vs. Segment vs. Frame

These terms overlap, which causes confusion. “Packet” is the most generic, used loosely at both the network and transport layers. “Datagram” specifically refers to a connectionless, independently routed unit of data. You’ll see it in two main places: IP datagrams at the network layer and UDP datagrams at the transport layer (the “D” in UDP stands for Datagram). “Segment” typically describes a TCP unit at the transport layer, while “frame” refers to the data unit at the link layer, where physical addressing like MAC addresses comes into play.

In casual conversation, people often use “packet” and “datagram” interchangeably. Technically, every datagram is a packet, but not every packet is a datagram, since the term datagram implies connectionless delivery.

Where Datagrams Are Used in Practice

The entire internet runs on IP datagrams at the network layer. But at the transport layer, the choice between datagram-based communication (UDP) and connection-based communication (TCP) depends on what the application needs.

UDP datagrams have a tiny header of just 8 bytes, compared to TCP’s minimum of 20 bytes. UDP skips acknowledgments, retransmissions, and flow control entirely. This makes it faster and lighter, which is why it’s the protocol of choice for DNS lookups, where a quick question-and-answer exchange doesn’t need a full connection setup. Voice over IP (VoIP) and video streaming also rely on UDP because low latency matters more than perfect delivery. A dropped frame in a video call is better than pausing to wait for a retransmission. Online gaming uses UDP for the same reason.

For real-time media, protocols like the Real-time Transport Protocol (RTP) run on top of UDP, adding timestamps and sequence numbers so the application can detect missing or out-of-order packets and compensate, without the overhead of TCP’s full reliability machinery.

Origin of the Term

The term “datagram” was coined by French computer scientist Louis Pouzin in the early 1970s while developing CYCLADES, a packet-switched network at the French research laboratory IRIA. Pouzin’s work on connectionless packet switching directly influenced Vint Cerf and the design of TCP/IP, the protocol suite that became the foundation of the modern internet. The word itself is a blend of “data” and “telegram,” capturing the idea of a self-contained message dispatched without a prior arrangement between sender and receiver.