Why CoAP Uses UDP for IoT Communication
The Constrained Application Protocol (CoAP) is a specialized web transfer protocol designed specifically for resource-constrained Internet of Things (IoT) devices and Low-power and Lossy Networks (LLNs). Unlike traditional web architectures that rely on HTTP over TCP, CoAP runs over the User Datagram Protocol (UDP). This article explains the primary technical reasons why UDP is the ideal transport layer protocol for CoAP, highlighting its low overhead, connectionless architecture, native multicast capabilities, and energy efficiency.
Minimal Protocol Overhead
Resource-constrained IoT devices typically operate with limited RAM, ROM, and processing power. Standard TCP headers are at least 20 bytes long, whereas UDP headers are fixed at just 8 bytes. By pairing CoAP’s compact 4-byte base header with UDP’s lightweight header, data packets remain small. This reduction in packet size is crucial for networks utilizing IEEE 802.15.4, which limits the physical layer packet size to 127 bytes, helping avoid costly packet fragmentation at the network layer.
Connectionless Architecture and Reduced Latency
TCP requires a three-way handshake (SYN, SYN-ACK, ACK) to establish a connection before transmitting any payload, followed by a four-way handshake to close it. In IoT scenarios where devices wake up, transmit a single sensor reading, and immediately return to deep sleep, this handshake introduces unacceptable latency and radio airtime. UDP is connectionless and sends datagrams immediately without prior channel establishment, significantly reducing transmission delays and optimizing duty cycles.
Native Support for Multicast
Group communication is essential in IoT ecosystems—for example, sending a single command to turn off all smart lights in a room or querying status updates from a cluster of environmental sensors. UDP natively supports IP multicast, allowing a single CoAP request to be broadcast to multiple devices simultaneously. TCP is strictly point-to-point (unicast) and cannot support multicast transmissions without establishing separate, resource-draining connections to each node.
Application-Layer Reliability (Best of Both Worlds)
While UDP does not guarantee packet delivery, CoAP does not require transport-layer reliability to function reliably. Instead, CoAP implements its own lightweight reliability mechanism using two basic message types:
- Confirmable (CON): Requires an explicit Acknowledgment (ACK) message from the receiver, with built-in retransmission timers and exponential backoff.
- Non-Confirmable (NON): Used for non-critical periodic data (like temperature updates) where dropped packets can be safely ignored.
This design gives IoT developers the flexibility to choose when reliability is necessary on a per-message basis, avoiding the mandatory overhead, flow control, and heavy state-tracking buffers of TCP.
Superior Energy Efficiency
For battery-powered IoT devices, the radio transceiver is the largest consumer of power. Because UDP eliminates connection management handshakes, reduces total payload size, and allows application-level control over retransmissions, it drastically minimizes the amount of time the device’s radio needs to remain active. This directly extends the operational battery life of remote nodes.