TOP

ASN.1 Encoding Rules Overview and Examples


ASN.1 defines several encoding rules that specify exactly how data structures and protocol messages are represented in binary or text form for communication between systems. Each set of rules offers different trade-offs such as compactness, speed, or human readability, making it suitable for particular environments.

The table below summarizes the ASN.1 encoding rules and highlights the differences in purpose, key characteristics, and typical usage environments. Each rule represents the same ASN.1 message in a different way, optimized for requirements such as compactness, speed, or readability.

Encoding Rule Purpose and Typical Use Key Characteristics
BER (Basic Encoding Rules) Flexible, general-purpose binary encoding used for interoperability and legacy ASN.1 systems.
  • TLV format
  • Self-describing
  • Multiple valid encodings
  • Not compact
DER (Distinguished Encoding Rules) Canonical form of BER used where deterministic encoding is required, especially in security.
  • Single valid encoding
  • Strict ordering
  • Widely used in PKI and cryptography
CER (Canonical Encoding Rules) Canonical BER variant optimized for very large or streaming data.
  • Uses indefinite-length encoding
  • Segmentation of long values
PER / UPER (Packed Encoding Rules) Highly compact binary encoding for bandwidth-constrained environments such as LTE/5G and IoT.
  • Removes TLV redundancy
  • Uses schema constraints
  • UPER bit-packs
OER (Octet Encoding Rules) Fast binary encoding optimized for encoding/decoding speed in real-time systems.
  • Octet-aligned
  • Easier to encode/decode than PER
  • Moderately compact
XER / E-XER (XML Encoding Rules) Human-readable XML representation mainly used for debugging and XML-based workflows.
  • XML <tag>value</tag> format
  • Large encoded size
JER (JSON Encoding Rules) JSON-based representation for modern web services and development workflows.
  • Interoperable with web frameworks
  • Preserves type constraints

Simple Example: Same ASN.1 Value Encoded Using Different Rules

The following example shows how constraint optimization affects PER and how BER/DER rely on TLV structure, while XER/JSON provide readability.

ASN.1:

 Temperature ::= INTEGER (-40..215)
   currentTemperature Temperature ::= 22
Encoding Rule Encoded Representation Notes
BER / DER / CER 02 01 16 (hex) Tag=INTEGER (0x02), Length=1, Value=22 (0x16)
PER 10110 (binary) Encoded using only 8 bits or fewer depending on constraint
OER 16 (hex) Octet-aligned value
XER <Temperature>22</Temperature> Human-readable XML
JSON { "Temperature": 22 } Human-readable JSON

Further Reading and Related Topics

BER, DER, CER

BER uses a flexible Tag-Length-Value binary format in which each field includes a tag, a length, and a value. DER and CER are canonical subsets of BER that remove ambiguity. DER is widely used in security-critical applications such as X.509 digital certificates.

See also

OER

OER produces compact encodings and prioritizes encoding/decoding speed. All values are octet-aligned, making processing significantly faster. It is used in Intelligent Transportation Systems and similar environments.

See also

PER / UPER

PER generates the most compact binary encoding by eliminating redundant TLV fields and applying ASN.1 constraints; UPER achieves additional compactness via bit packing. It is common in 3GPP/LTE/5G and bandwidth-limited protocols.

See also

XER / E-XER

XER represents values as XML for readability. E-XER improves compatibility with XML Schema tooling. Typically used for debugging and browser visualization.

See also

JER

JSON encoding maps ASN.1 values to JSON syntax while preserving constraints and type information, enabling efficient interaction with modern web technology.

Try It Yourself

Experiment with different encoding rules in the ASN.1 Playground.

Try encoding:

currentTemperature Temperature ::= 22
See also