CBOR, short for Concise Binary Object Representation, is a self-describing binary data format standardized by the IETF in RFC 8949 that encodes numbers, strings, arrays, maps and tagged values in a compact byte sequence. Among data formats, CBOR occupies the space between human-readable text such as JSON and schema-bound binary encodings such as Protocol Buffers: it needs no schema to decode, yet it produces smaller messages and faster parsing than text.
The format was designed with explicit goals: very small encoder and decoder code, extensibility without version negotiation, and suitability for constrained devices such as sensors and microcontrollers. It is the native encoding of several security and Internet of Things protocols, including COSE, CWT, WebAuthn and the Constrained Application Protocol ecosystem.
How CBOR encodes a data item
Every CBOR value begins with an initial byte that splits into a 3-bit major type and a 5-bit additional information field. The major type says what kind of item follows, and the additional information either holds a small value directly or announces how many following bytes carry the length or value.
Values from 0 to 23 fit inside the initial byte itself, so the integer 10 or a five-character string header costs a single byte. Values 24, 25, 26 and 27 signal that a 1-, 2-, 4- or 8-byte unsigned integer follows in big-endian order. This length-prefixed design lets a decoder skip any item without understanding its content, which is essential for forward compatibility.
The table below lists the eight major types and what each one represents.
| Major type | Meaning | Argument encodes |
|---|---|---|
| 0 | Unsigned integer | The value itself |
| 1 | Negative integer | Minus one minus the value |
| 2 | Byte string | Length in bytes |
| 3 | Text string (UTF-8) | Length in bytes |
| 4 | Array | Number of items |
| 5 | Map | Number of key-value pairs |
| 6 | Tag | Tag number for the next item |
| 7 | Simple values and floats | false, true, null, undefined, float size |
Major type 7 also carries half-, single- and double-precision floats (16, 32 and 64 bits) and the break code that terminates indefinite-length items. Arrays, maps and strings may be sent with an indefinite length and closed by that break byte, which allows a producer to stream data whose size is unknown in advance.
Tags, extensibility and deterministic encoding
A tag (major type 6) attaches a semantic meaning to the item that follows it, without changing how that item is parsed. A decoder that does not recognize a tag can still read the enclosed value, so new semantics can be added without breaking older implementations. Tag numbers are registered with IANA, and many are widely supported.
| Tag number | Enclosed item | Semantics |
|---|---|---|
| 0 | Text string | Date and time in RFC 3339 form |
| 1 | Integer or float | Epoch-based date and time |
| 2 and 3 | Byte string | Unsigned and negative bignums |
| 4 | Array | Decimal fraction |
| 24 | Byte string | Embedded encoded CBOR item |
| 37 | Byte string | Binary UUID |
| 55799 | Any item | Self-described CBOR magic prefix |
Because the same value can often be written in more than one valid way, RFC 8949 defines core deterministic encoding requirements: use the shortest integer and length forms, avoid indefinite lengths, and sort map keys by their encoded bytes. Deterministic encoding matters whenever a value is hashed or signed, because the signer and the verifier must produce identical bytes. The companion specification CDDL (Concise Data Definition Language, RFC 8610) offers an optional notation for describing the expected structure of CBOR messages when a protocol needs one.
CBOR compared with other binary and text data formats
CBOR is best understood as a binary superset of the JSON data model: it represents everything JSON can, and adds byte strings, tags, undefined and precise float widths. Its closest neighbor is MessagePack, from which it borrowed ideas, while BSON and Protocol Buffers sit further away in design intent.
| Format | Schema needed | Binary data | Main design goal |
|---|---|---|---|
| CBOR | No | Native byte strings | Small code, extensibility, IETF protocols |
| JSON | No | Base64 text only | Human readability, web interchange |
| MessagePack | No | Native | Compact replacement for JSON |
| BSON | No | Native | Traversable storage in a document database |
| Protocol Buffers | Yes | Native | Fast typed messages between services |
Compared with MessagePack, CBOR offers a formal standard track, a registered tag mechanism and a defined deterministic profile, while MessagePack relies on application-defined extension types. Compared with Protocol Buffers, CBOR messages are somewhat larger because field names usually travel inside every map, but the receiver needs no generated code to inspect them. Size gains over JSON vary with content: numeric and binary payloads shrink considerably, while text-heavy documents shrink only modestly.
Where CBOR is used and how to apply it
CBOR is chosen when messages must be compact, schema-free and cheap to parse on limited hardware, or when a security protocol needs signed binary structures. It is less common in analytics pipelines, where columnar formats such as Parquet dominate.
- COSE (CBOR Object Signing and Encryption) and CWT (CBOR Web Token) provide signatures, encryption and tokens for constrained environments.
- WebAuthn and FIDO2 encode authenticator data and attestation objects in CBOR.
- CoAP-based IoT systems frequently carry sensor readings as CBOR payloads.
- Digital credentials, including the mobile driving license data model in ISO/IEC 18013-5, rely on CBOR structures.
The decision table below summarizes when CBOR is a sound choice.
| Situation | Recommended choice | Reason |
|---|---|---|
| Battery-powered sensor sending readings | CBOR | Small payload, tiny decoder |
| Signed token or credential | CBOR with deterministic encoding | Stable bytes for signatures |
| Public web API read by humans | JSON | Readability and tooling |
| High-volume typed service calls | Protocol Buffers | Schema enforcement, smaller messages |
| Large analytical tables | Parquet or Apache Arrow | Columnar compression and scans |
Limitations and common mistakes with CBOR
CBOR is not human-readable, so debugging requires a diagnostic tool that renders the diagnostic notation, a JSON-like text view defined in the specification. Teams that skip such tooling often misread payloads or blame the wrong component.
| Symptom | Cause | Fix |
|---|---|---|
| Signature fails to verify | Non-deterministic map order | Apply core deterministic encoding |
| Decoder runs out of memory | Untrusted length fields | Set limits on length and nesting depth |
| Data loss after JSON conversion | Byte strings and tags unsupported in JSON | Define an explicit mapping |
| Interoperability errors | Duplicate map keys | Reject duplicates on decode |
A frequent misconception is that CBOR is simply compressed JSON. It is a separate encoding with a richer data model, and it does not compress repeated strings by itself. A second risk is decoding untrusted input without limits: an attacker can declare enormous lengths or deep nesting, so robust decoders validate sizes before allocating memory.
Stripped to the essentials
CBOR is a way of packing structured information, such as numbers, names and lists, into as few bytes as possible. Text formats spell everything out in letters. CBOR instead uses short binary codes that a computer reads almost instantly.
Think of it as shorthand for machines. A receipt written in full sentences is easy for people to read but long. The same receipt written in agreed abbreviations is shorter and quicker to process, and anyone who knows the abbreviations can still read it without a separate instruction sheet. That is why small devices and security systems like it: less data to send and less work to understand it.
Where it is applied
A water utility deploys several thousand battery-powered flow meters that report over a low-power radio network with payloads limited to a few dozen bytes. Each reading contains a meter identifier, a timestamp, a flow value and a status flag. Encoded as JSON, a typical reading needs roughly 90 bytes and does not fit in a single radio frame.
The engineering team switches the payload to CBOR with integer map keys and an epoch timestamp under tag 1. The same reading now occupies about 25 bytes, fits into one frame, and the firmware decoder adds only a few kilobytes of code. At the head end, a gateway converts the CBOR into JSON for the analytics platform. The result is fewer retransmissions and longer battery life, while operators still inspect raw messages through the diagnostic notation when troubleshooting.