CBOR Encode/Decode
Online CBOR encode/decode tool with JSON and CBOR conversion, hex, Base64, C-array output, and container length modes for IoT and embedded protocol debugging.
Paste CBOR data captured from packet tools, IoT devices, or API responses.
Click to insert example data
Decoded Result
Enter CBOR data to decode and view result
CBOR Protocol Guide
What is CBOR
CBOR (Concise Binary Object Representation) is a binary serialization format defined by RFC 8949. It keeps compatibility with the JSON data model while providing compact size and efficient parsing for IoT, embedded, and security scenarios.
Binary Structure
Each CBOR item starts with one byte. The top 3 bits represent the major type and the lower 5 bits represent additional information, which can encode small values directly or indicate following length bytes.
| Additional Info | Meaning |
|---|---|
| 0-23 | Value encoded directly in additional info |
| 24 | Followed by 1-byte unsigned integer |
| 25 | Followed by 2-byte unsigned integer (big-endian) |
| 26 | Followed by 4-byte unsigned integer (big-endian) |
| 27 | Followed by 8-byte unsigned integer (big-endian) |
| 31 | Indefinite-length container ended by 0xFF |
CBOR Data Type 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 | Arbitrary binary byte sequence |
| 3 | Text String | 0x60-0x7B | UTF-8 encoded text string |
| 4 | Array | 0x80-0x9B | Ordered collection of data items |
| 5 | Map | 0xA0-0xBB | Key-value object map |
| 6 | Tag | 0xC0-0xDB | Semantic tags for extended meaning |
| 7 | Simple/Float | 0xE0-0xFB | Booleans, null, undefined, and floating numbers |
Container Length Modes
Arrays and maps can be encoded with different length modes. They are semantically equivalent but differ at binary level for compatibility and streaming needs.
| Mode | Header Bytes | Description |
|---|---|---|
| Compact | A2 ... | Minimum-size encoding with compact headers |
| Explicit 16-bit | B9 00 02 ... | Always use 2-byte length field |
| Explicit 32-bit | BA 00 00 00 02 ... | Always use 4-byte length field |
| Indefinite | BF ... FF | Indefinite containers for streaming writers |
CBOR vs JSON
Both formats represent the same logical structure. JSON emphasizes readability, while CBOR emphasizes compactness and processing efficiency.
- Smaller payload size and lower network overhead
- Native support for binary data
- Usually faster encoding and decoding
- Semantic tags for richer type expression
- Human-readable and easy to inspect
- Broad language and browser support
- Convenient for logs and troubleshooting
Common Use Cases
- IoT device communication and sensor payload transfer
- WebAuthn/FIDO2 authentication data analysis
- COSE (CBOR Object Signing and Encryption) security workflows
- CoAP constrained application message exchange
- Embedded device configuration and data storage
Semantic Tags
Tags provide semantic meaning for CBOR items, allowing richer interpretation without changing the base binary structure.
| 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 marker |