Resources
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. |
|
| DER (Distinguished Encoding Rules) | Canonical form of BER used where deterministic encoding is required, especially in security. |
|
| CER (Canonical Encoding Rules) | Canonical BER variant optimized for very large or streaming data. |
|
| PER / UPER (Packed Encoding Rules) | Highly compact binary encoding for bandwidth-constrained environments such as LTE/5G and IoT. |
|
| OER (Octet Encoding Rules) | Fast binary encoding optimized for encoding/decoding speed in real-time systems. |
|
| XER / E-XER (XML Encoding Rules) | Human-readable XML representation mainly used for debugging and XML-based workflows. |
|
| JER (JSON Encoding Rules) | JSON-based representation for modern web services and development workflows. |
|
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 |
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.
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.
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.
XER represents values as XML for readability. E-XER improves compatibility with XML Schema tooling. Typically used for debugging and browser visualization.
JSON encoding maps ASN.1 values to JSON syntax while preserving constraints and type information, enabling efficient interaction with modern web technology.
Experiment with different encoding rules in the ASN.1 Playground.
Try encoding:
currentTemperature Temperature ::= 22