What is CoAP (Constrained Application Protocol)?
Updated: Oct 27

CoAP (Constrained Application Protocol) is a compact application protocol that lets devices request and update resources, such as a temperature reading or a control setting, on other devices. It brings a web-style resource model to equipment with limited memory, processing power or network capacity. Its original design uses UDP, with optional acknowledgement and retransmission at the CoAP layer; later standards also support reliable transports.
A controller can ask a sensor for /temperature without a message broker sitting between them. The important distinction is that a CoAP message being acknowledged, a useful response arriving and a physical action completing are separate events. Understanding those layers makes CoAP easier to design, secure and troubleshoot.
How does CoAP work?
An endpoint acts as a client when it makes a request and as a server when it handles one. A small sensor can therefore be a server: server describes its role in an exchange, not the size of the computer. The resource is the item being addressed; its representation is the data returned, such as a text value or a structured measurement.
The controller selects the sensor endpoint and resource path, for example /temperature.
It sends a GET request, with a Token for matching the eventual response to that request.
The sensor checks the request, permissions and resource. If the answer is ready, it can return the representation immediately.
The controller checks the response code, matching information, content format and freshness before using the value.
For a control operation, the application separately defines what success means and how to confirm the equipment reached the intended state.
The IETF’s RFC 7252, published in June 2014 as a standards-track specification and currently listed as a Proposed Standard, defines the base protocol. Extensions add functions such as observation and block-wise transfer. Implementations support different combinations, so two products labelled CoAP still need compatible transport, security and application conventions.
The infographic follows CoAP over UDP. It compares an immediate answer with a delayed answer, where the first acknowledgement contains no application response. Message IDs and Tokens have deliberately different jobs.

Resources, methods and response codes
CoAP uses methods familiar from web APIs, but it is a separate wire protocol. The resource path and other metadata are carried through compact options rather than a textual HTTP request line. A resource named /temperature does not define its units, calibration or data model by itself; the application must specify those meanings.
Method | Intended operation |
|---|---|
GET | Retrieve a representation without requesting a state-changing operation. |
PUT | Create or replace the state at the specified resource URI, subject to server support. |
POST | Ask the resource to process the supplied representation; the application defines the operation. |
DELETE | Remove the resource identified by the request URI, where permitted. |
GET is safe and idempotent in protocol semantics. PUT and DELETE are idempotent, although they change state; POST is not generally idempotent. Idempotency means repeating the same intended operation has the same intended effect, rather than repeatedly incrementing or triggering something. Applications still need permission checks and recovery logic.
Response codes use a class and detail, such as 2.05 Content, 2.04 Changed or 4.04 Not Found. A response can be successfully delivered while reporting an application error. An ACK message is not synonymous with a successful response, and an Empty ACK contains no response at all.
CoAP over UDP: four message types
Type | Purpose |
|---|---|
CON: Confirmable | Requests acknowledgement. The sender retries with back-off if no acknowledgement or reset arrives, within configured limits. |
NON: Non-confirmable | Does not request acknowledgement at the message layer. A request may still receive an application response. |
ACK: Acknowledgement | Acknowledges a matching Confirmable message. It can carry an immediate response or be empty. |
RST: Reset | Rejects a message when the receiver lacks the context to process it correctly; it is not an ordinary application error response. |
Reliability here comes from CoAP’s message machinery, not from UDP guaranteeing delivery. Retries can recover loss, but a timeout can still occur after the server acted and its reply was lost. Starting a new application request after that timeout can repeat work. Use operation identifiers, safe state-setting semantics and outcome checks where repetition would matter.
Message ID versus Token
For UDP CoAP, the Message ID identifies a message exchange for acknowledgement matching and duplicate detection. The Token associates a response with a request, together with the relevant endpoint information. They are not interchangeable. A separate response has its own Message ID but echoes the request Token.
An illustrative request might use Message ID 100 and Token A7. An immediate response can be carried in ACK 100 with Token A7. That is a piggybacked response: one returning message both acknowledges the request message and supplies the answer.
Why an Empty ACK is not the answer
The client sends a Confirmable GET with Message ID 100 and Token A7.
The server returns Empty ACK 100. This stops retransmission of that request message, but supplies neither the requested value nor a success response code.
When ready, the server sends a separate Confirmable response, for example 2.05 Content with Message ID 200 and the original Token A7.
The client returns Empty ACK 200 to acknowledge that response message.
This is one valid separate-response sequence, not the only allowed response pattern. The client still needs an application response deadline. Receipt of an Empty ACK must not leave a dashboard displaying a permanently pending request or a controller assuming the requested action completed.
The base UDP defaults include an initial acknowledgement timeout randomised between 2 and 3 seconds and a maximum of four retransmissions, with increasing intervals. These are protocol defaults, not a promise of response latency. Do not slash timers to make a slow system appear responsive without understanding congestion control and the actual network.
Why a four-byte header does not mean four bytes of overhead
The original UDP format begins with a fixed four-byte header, then a variable Token, options and, when present, a payload marker and payload. The Token length allowed by the base specification was extended by RFC 8974 in 2021. Neither the base header size nor an older Token limit describes every modern CoAP transport and extension.
Content-Format identifies how a payload is encoded; Accept can express the desired response format. JSON, CBOR and application-specific formats are possible when both endpoints support them. CoAP does not automatically turn an arbitrary binary payload into a meaningful measurement.
Techie Broadband calculation: one small response
Assume a UDP CoAP response contains a four-byte base header, a two-byte Token, three bytes of encoded options, a one-byte payload marker and a 20-byte payload. These illustrative choices produce 30 bytes of CoAP data. Adding the eight-byte UDP header gives 38 bytes. With an ordinary 20-byte IPv4 header and no options, the IP packet is 58 bytes; a 40-byte IPv6 base header instead makes it 78 bytes.
Illustrative layer total | Bytes |
|---|---|
CoAP message including 20-byte payload | 30 |
UDP datagram including CoAP message | 38 |
IPv4 packet with ordinary base header | 58 |
IPv6 packet with base header only | 78 |
This is arithmetic, not a packet capture or a universal size claim. It excludes link-layer framing, adaptation-layer compression or fragmentation, IPv6 extension headers, DTLS or OSCORE, acknowledgements, retransmissions and setup. On a small radio link, those factors and time spent awake can matter more than the application payload. A percentage saving against HTTP would require a fair, specified comparison of complete exchanges.
Observe and caching: freshness matters
RFC 7641, the September 2015 standards-track Observe extension, lets a client register interest in an observable resource and receive updated representations. This can reduce repeated polling. The server does not need a separate message broker to provide that relationship.
Observe follows a best-effort state-synchronisation model. It can skip intermediate states, and messages can arrive late or out of order. The Observe sequence value helps identify newer notifications; it is not a historical event number guaranteeing that every transition was delivered. Use a separate event-recording design if every alarm transition or financial event must be retained.
Max-Age limits how long a representation can be treated as fresh. Under the base caching rules, an absent Max-Age means 60 seconds; an application needing a shorter lifetime must arrange suitable values. An ETag identifies a representation for validation. A cached answer can be protocol-fresh while still unsuitable for a control decision with a much tighter age requirement.
Polling versus observation: count the whole exchange
For a clearly labelled example, 60 sensors polled once every 10 seconds create six requests and six responses per second, before loss or extra traffic. If each sensor changes only once per minute, an Observe design would average one notification per second across the group. Registration, acknowledgements for Confirmable notifications, refresh, reconnection and security traffic are additional. This demonstrates a workload difference, not a measured battery-life saving.
Discovery, block-wise transfers and proxies
CoRE Link Format resource discovery, defined in RFC 6690, commonly uses /.well-known/core to describe resources the server chooses to expose. Discovery is not permission to control a device, and a server may restrict what it advertises. A response’s actual Content-Format remains more authoritative than a discovery hint.
RFC 7959’s block-wise transfer handles larger representations across multiple exchanges. Block1 concerns the request body, while Block2 concerns the response body. Choosing smaller blocks can suit memory and packet-size constraints, but adds exchanges and sensitivity to round-trip delay. It does not make a firmware update automatically authentic, atomic or safe to install.
CoAP proxies can forward requests, cache eligible representations or translate between CoAP and HTTP. Translation needs defined semantics, error handling, security boundaries and freshness policy. A gateway cannot fix an ambiguous data model merely by changing the transport.
UDP is the original transport, not the only one
RFC 8323, published in February 2018, defines CoAP over TCP, TLS and WebSockets. Reliable transports replace the UDP message-layer reliability mechanism: the TCP form removes the UDP Type and Message ID fields rather than wrapping the same CON/ACK exchange unchanged. Tokens still match responses to requests.
Transport choice affects interoperability, memory, connection setup, loss recovery and middlebox behaviour. CoAP remains an application protocol; it is not a radio technology or a replacement for IP routing. A browser also does not automatically gain native CoAP access simply because an application exposes a CoAP resource.
DTLS, OSCORE and device permissions
Plain CoAP does not encrypt a reading or authenticate a controller. DTLS can protect datagram transport, while TLS protects reliable transport variants. Keys, trust, peer identity and resource-level authorisation still need correct provisioning. The conventional UDP ports are 5683 for CoAP and 5684 for DTLS-secured CoAP, but the listener’s configuration determines what actually operates there.
The IETF’s OSCORE specification, RFC 8613 from July 2019, protects selected CoAP message content at the application layer, including across supported intermediaries. That differs from DTLS terminating at a proxy, where transport protection ends at that proxy. OSCORE does not conceal every outer field, eliminate key management or make a compromised endpoint trustworthy.
RFC 9175 updated token processing and added Echo and Request-Tag mechanisms in 2022 to address particular security problems. Use maintained libraries and check support for relevant updates rather than implementing only an old tutorial’s packet format. RFC 9876’s 2025 update concerns Content-Format registration procedures; it does not replace these transport or security rules.
Authenticate the intended peer and restrict access to each resource and method.
Protect credentials and keys, plan rotation and verify behaviour after a device restart.
Rate-limit requests and avoid exposing unauthenticated endpoints that can be abused for amplification.
Validate payload format, units, permitted values and freshness before acting.
Treat a successful protocol response as evidence only for the outcome the application actually defines.
What CoAP means for UK broadband and local networks
A local controller reading a local sensor can operate without a WAN path if its addressing, power, routing and application dependencies are local. A cloud controller or remote gateway adds broadband, ISP and wider network dependencies. A faster headline package does not resolve radio loss, sleeping-device behaviour, an overloaded gateway or a blocked UDP path.
For remote access to a home-hosted endpoint, CGNAT can prevent straightforward unsolicited inbound IPv4 traffic. UDP mapping timeouts and firewall policy can also affect long-lived observations. An outbound gateway architecture may change the connectivity problem, but still needs authentication and a deliberate failure policy. Do not expose an unprotected control interface as a diagnostic shortcut.
Trace the complete path: controller, LAN or radio segment, gateway, router, access network and remote endpoint. Compare local and remote behaviour. If only the remote path fails, inspect routing, address family, security and network policy before blaming the sensor or buying more bandwidth.
A safe read-only CoAP check
The official libcoap client manual documents method selection, observation and logging options. The following examples assume its coap-client executable is installed and an authorised test server is already listening on 127.0.0.1:5683. They use loopback, do not create a public listener and do not alter a device. Package builds may use a suffixed executable name; check the installed manual. Command options are documentation-verified; no successful runtime result is claimed here.
coap-client -m get coap://127.0.0.1:5683/.well-known/core
Inspect the returned resource links and choose an actually advertised readable resource. If this test server exposes /temperature, the next command requests it. A 4.04 response means that path was not found, rather than proving all CoAP communication failed.
coap-client -m get coap://127.0.0.1:5683/temperature
For a test resource documented as observable, libcoap’s -s 30 option requests observation for 30 seconds. It cannot force an ordinary resource to support Observe. Secure endpoints need their correct scheme and trust configuration; do not disable verification to obtain a result. A successful loopback GET tests that local exchange only, not the radio path, WAN, power-loss recovery or physical accuracy of the sensor.
Troubleshooting a missing or stale CoAP response
Identify the exchange and endpoint roles. Confirm which resource and method should work, and whether the failure is local or only remote.
Check the exact scheme, IP address family, port, path and transport. UDP and TCP listeners are different, even at the same numeric port.
Inspect credentials, trust and resource permissions. Separate a security handshake failure from a CoAP error response.
Read Message IDs, Tokens and response codes with an authorised diagnostic tool. An Empty ACK means wait for the separate response, not operation complete.
For timeouts, inspect loss, device sleep, gateway load and both directions of the path. Retrying a non-idempotent operation needs an application policy.
For stale readings, check observation registration, sequence handling, Max-Age, payload timestamps and cache behaviour.
For large transfers, compare block-wise support, block sizes, memory and fragmentation. Do not assume a small GET proves firmware transfer will work.
After a restart or route change, verify observations and security state recover as designed. Record the actual outcome rather than inferring it from a live socket.
CoAP, MQTT or HTTP?
Need | Useful starting point |
|---|---|
Direct access to constrained-device resources | CoAP, with compatible transport, security and data model. |
One producer sending to several independent consumers | MQTT’s broker-based publish/subscribe model may suit the routing requirement. |
A conventional web API with broad tooling | HTTP may simplify integration; account for the actual device and security budget. |
Every event retained and audited | Specify durable application storage and delivery semantics; no protocol label alone establishes this. |
Our MQTT guide explains the broker model and its delivery limits. Choose by the required interaction, supported libraries, security lifecycle and failure recovery. CoAP is not automatically lower-energy than every HTTP or MQTT deployment: polling frequency, radio wake time, security setup and retries can dominate the result.
CoAP questions answered
Does CoAP require a broker?
No. A client can request a resource directly from a CoAP server. Proxies, gateways and resource directories can be useful architectural components, but a central message broker is not a requirement of the basic interaction.
Is CoAP reliable even though it uses UDP?
Confirmable UDP messages add acknowledgement and bounded retransmission at the CoAP layer. They improve delivery under loss but cannot guarantee that every request completes or that a physical action happens exactly once. Non-confirmable requests can still receive application responses.
Is Observe the same as a durable subscription queue?
No. Observe keeps a client informed about resource representations on a best-effort basis. It can miss intermediate states and does not provide a complete persistent event history for an offline consumer.
Can CoAP work without the internet?
Yes, when the communicating endpoints and their required services are reachable locally. Remote endpoints and cloud-dependent applications need a working route to those services. Local connectivity does not remove power, security or recovery requirements.
Key takeaway
CoAP makes resource-oriented communication practical on constrained equipment. Design around the complete exchange: the endpoint, method, matching response, freshness, protection and application outcome. Its compact format is useful, but dependable operation comes from making those relationships explicit. The broadband terminology guide provides the wider networking context.

