CBOR

Also known as: Concise Binary Object Representation

On this page 7

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 typeMeaningArgument encodes
0Unsigned integerThe value itself
1Negative integerMinus one minus the value
2Byte stringLength in bytes
3Text string (UTF-8)Length in bytes
4ArrayNumber of items
5MapNumber of key-value pairs
6TagTag number for the next item
7Simple values and floatsfalse, true, null, undefined, float size
The eight CBOR major types

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 numberEnclosed itemSemantics
0Text stringDate and time in RFC 3339 form
1Integer or floatEpoch-based date and time
2 and 3Byte stringUnsigned and negative bignums
4ArrayDecimal fraction
24Byte stringEmbedded encoded CBOR item
37Byte stringBinary UUID
55799Any itemSelf-described CBOR magic prefix
Commonly used CBOR tags

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.

FormatSchema neededBinary dataMain design goal
CBORNoNative byte stringsSmall code, extensibility, IETF protocols
JSONNoBase64 text onlyHuman readability, web interchange
MessagePackNoNativeCompact replacement for JSON
BSONNoNativeTraversable storage in a document database
Protocol BuffersYesNativeFast typed messages between services
How CBOR relates to neighboring serialization formats

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.

SituationRecommended choiceReason
Battery-powered sensor sending readingsCBORSmall payload, tiny decoder
Signed token or credentialCBOR with deterministic encodingStable bytes for signatures
Public web API read by humansJSONReadability and tooling
High-volume typed service callsProtocol BuffersSchema enforcement, smaller messages
Large analytical tablesParquet or Apache ArrowColumnar compression and scans
Choosing CBOR by situation

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.

SymptomCauseFix
Signature fails to verifyNon-deterministic map orderApply core deterministic encoding
Decoder runs out of memoryUntrusted length fieldsSet limits on length and nesting depth
Data loss after JSON conversionByte strings and tags unsupported in JSONDefine an explicit mapping
Interoperability errorsDuplicate map keysReject duplicates on decode
Typical CBOR problems and fixes

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.