CoderTools

CBOR Codec

Encode and decode CBOR binary data format

🔒 100% Local ProcessingYour input data is processed entirely in your browser. It is not uploaded to any server.

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

CBOR Data Types Reference

Major Type Type Name Header Bytes Description
0Unsigned Integer0x00-0x1BNon-negative integers from 0 to 2^64-1
1Negative Integer0x20-0x3BNegative integers from -1 to -2^64
2Byte String0x40-0x5BRaw binary data of arbitrary length
3Text String0x60-0x7BUTF-8 encoded text strings
4Array0x80-0x9BOrdered collection of data items
5Map0xA0-0xBBKey-value pairs (object)
6Tag0xC0-0xDBSemantic tag for extended types
7Simple/Float0xE0-0xFBBoolean, 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-23Value encoded directly (0-23)
241-byte unsigned follows
252-byte unsigned follows (big-endian)
264-byte unsigned follows (big-endian)
278-byte unsigned follows (big-endian)
31Indefinite 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
CompactA2 ...0xA2 = fixmap(2), smallest encoding
Explicit 16-bitB9 00 02 ...0xB9 = map16, 2-byte length follows
Explicit 32-bitBA 00 00 00 02 ...0xBA = map32, 4-byte length follows
IndefiniteBF ... FF0xBF = 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.

CBOR Advantages
  • Smaller encoded size (30-50% typical)
  • Native binary data support
  • Faster parsing and encoding
  • Built-in semantic tags for dates, URIs, etc.
JSON Advantages
  • 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
0Standard date/time string (RFC 3339)
1Epoch-based date/time (Unix timestamp)
2Positive bignum
3Negative bignum
32URI reference
55799Self-describe CBOR (magic number)

Quick Menu

No recent tools