CBOR Codec
Encode and decode CBOR binary data format
Paste CBOR data from network captures, IoT devices, or API responses
Click to Insert Example Data
Decoded Result
Enter CBOR data and click Decode to see results
Byte Viewer
Enter valid JSON data to encode as CBOR
Container Length Encoding
- Compact: Uses minimum bytes (fixmap/fixarray when ≤23 items)
- Explicit 16-bit: Always uses 2-byte length (0xB9/0x99 prefix)
- Explicit 32-bit: Always uses 4-byte length (0xBA/0x9A prefix)
- Indefinite: Uses indefinite length with break code (0xBF...0xFF)
Click to Insert JSON Example
Encoded Result
Enter JSON data and click Encode to generate CBOR
Byte Viewer
Encoding Statistics
CBOR Data Types Reference
| Major Type | Type Name | Header Bytes | Description |
|---|---|---|---|
| 0 | Unsigned Integer | 0x00-0x1B | Non-negative integers from 0 to 2^64-1 |
| 1 | Negative Integer | 0x20-0x3B | Negative integers from -1 to -2^64 |
| 2 | Byte String | 0x40-0x5B | Raw binary data of arbitrary length |
| 3 | Text String | 0x60-0x7B | UTF-8 encoded text strings |
| 4 | Array | 0x80-0x9B | Ordered collection of data items |
| 5 | Map | 0xA0-0xBB | Key-value pairs (object) |
| 6 | Tag | 0xC0-0xDB | Semantic tag for extended types |
| 7 | Simple/Float | 0xE0-0xFB | Boolean, null, undefined, and floating-point numbers |
CBOR Protocol Documentation
What is CBOR
CBOR (Concise Binary Object Representation) is a binary data serialization format defined in RFC 8949. Designed as a compact alternative to JSON, CBOR encodes structured data into efficient binary form while maintaining JSON's data model compatibility. The format is self-describing, meaning decoders can parse data without external schema definitions. CBOR was specifically engineered for constrained environments like IoT devices and embedded systems where bandwidth and processing power are limited resources.
Binary Encoding Structure
Every CBOR data item begins with a single byte containing two fields: the major type (3 bits) and additional information (5 bits). The major type determines the data category (integer, string, array, etc.), while additional information indicates the argument's length or holds small values directly. This compact header design means simple values like small integers require only a single byte.
| Additional Info | Meaning |
|---|---|
| 0-23 | Value encoded directly (0-23) |
| 24 | 1-byte unsigned follows |
| 25 | 2-byte unsigned follows (big-endian) |
| 26 | 4-byte unsigned follows (big-endian) |
| 27 | 8-byte unsigned follows (big-endian) |
| 31 | Indefinite length (for strings, arrays, maps) |
Container Length Encoding Options
CBOR provides flexibility in how container (array and map) lengths are encoded. While all valid encodings produce semantically identical data, the binary representation differs. This tool offers four encoding modes to match different system requirements.
Encoding Example: {"name":"Alice","age":30}
The same JSON object can be encoded in multiple valid ways:
| Mode | Header Bytes | Description |
|---|---|---|
| Compact | A2 ... | 0xA2 = fixmap(2), smallest encoding |
| Explicit 16-bit | B9 00 02 ... | 0xB9 = map16, 2-byte length follows |
| Explicit 32-bit | BA 00 00 00 02 ... | 0xBA = map32, 4-byte length follows |
| Indefinite | BF ... FF | 0xBF = indefinite map, ends with 0xFF break |
All four encodings decode to identical JSON. Choose compact for size efficiency, explicit lengths for protocol compatibility, or indefinite for streaming scenarios.
CBOR vs JSON Comparison
Both formats represent the same logical data model but serve different purposes. CBOR prioritizes compact encoding and processing efficiency, while JSON emphasizes human readability and universal text-based interoperability.
- Smaller encoded size (30-50% typical)
- Native binary data support
- Faster parsing and encoding
- Built-in semantic tags for dates, URIs, etc.
- Human readable and editable
- Universal browser/language support
- Easier debugging and logging
Common Applications
- IoT device communication and sensor data transmission
- WebAuthn/FIDO2 authentication protocols
- COSE (CBOR Object Signing and Encryption) security
- CoAP (Constrained Application Protocol) messaging
- Embedded systems configuration and data storage
Semantic Tags
CBOR tags provide semantic meaning to data items. Tags are optional wrappers that indicate how the enclosed value should be interpreted, enabling type extensions beyond basic data types.
| Tag Number | Semantic Meaning |
|---|---|
| 0 | Standard date/time string (RFC 3339) |
| 1 | Epoch-based date/time (Unix timestamp) |
| 2 | Positive bignum |
| 3 | Negative bignum |
| 32 | URI reference |
| 55799 | Self-describe CBOR (magic number) |
Related Tools
Protocol Buffers Tool
Online Protocol Buffers encoder/decoder. Parse .proto schemas, encode JSON to binary, or decode binary to JSON
JSON Formatter
Format and validate JSON data for improved readability and debugging
Base64 Encoder/Decoder
Quickly encode and decode Base64 strings, supporting both text and file conversion
MQTT Codec
Encode and decode MQTT protocol packets with detailed field breakdown, hex viewer, and packet builder