What Is Abstract Syntax Notation One (ASN.1)?

May 8, 2024

Abstract Syntax Notation One (ASN.1) is a standardized notation used for defining data structures that can be serialized and deserialized across different platforms. It provides a framework for describing data in a platform-independent way, making it crucial for communication protocols.

What Is ASN.1?

Abstract Syntax Notation One (ASN.1) is a standardized notation developed by the International Telecommunication Union (ITU-T) for specifying data structures in a platform-independent manner. It plays a critical role in telecommunications, networking, and security protocols by offering a formal language to describe complex data structures. ASN.1 separates data syntax from encoding, allowing data to be transmitted and processed seamlessly across various systems.

Its encoding rules, such as Basic Encoding Rules (BER), Distinguished Encoding Rules (DER), and Packed Encoding Rules (PER), ensure that the serialized data is efficiently transmitted while maintaining structural fidelity. ASN.1 defines not just the types and values of data, but also how these data structures relate to each other, making it indispensable in areas where precise and interoperable data exchange is necessary. It is especially useful in security applications, digital certificates, and telecommunication standards where consistency in data handling is crucial.

ASN.1 Syntax Example

Here's an example of ASN.1 syntax demonstrating a simple message structure for a person with a name and an age:

Person DEFINITIONS ::= BEGIN PersonRecord ::= SEQUENCE { name UTF8String, age INTEGER } END

In this example, the module Person contains a structure called PersonRecord which is defined as a SEQUENCE. This sequence includes two fields:

  1. name, which is a UTF8String.
  2. age, which is an INTEGER.

ASN.1 Encoding Example

Suppose we want to define a structure for a person with two fields: name (a string) and age (an integer). This would be written in ASN.1 as follows:

Person DEFINITIONS ::= BEGIN PersonRecord ::= SEQUENCE { name UTF8String, age INTEGER } END

Data Example

Assume we want to represent a person named "Alice" who is 30 years old.

Encoding Example

If we use BER (Basic Encoding Rules) for encoding, the data for "Alice, 30" would be serialized as follows:

  1. Sequence Identifier: 0x30 (indicating a SEQUENCE)
  2. Length: 0x0C (12 bytes for the whole sequence)
  3. UTF8String Identifier: 0x0C (indicating UTF8String)
  4. Length of name: 0x05 (5 bytes for the name "Alice")
  5. Value of name: 0x41 0x6C 0x69 0x63 0x65 (UTF-8 encoded "Alice")
  6. INTEGER Identifier: 0x02 (indicating INTEGER)
  7. Length of age: 0x01 (1 byte for the integer)
  8. Value of age: 0x1E (30 in hexadecimal)

Thus, the BER-encoded data would look like this:

30 0C 0C 05 41 6C 69 63 65 02 01 1E

This hexadecimal representation corresponds to the data structure defined in ASN.1, showing how it can be used to exchange data between systems consistently.

ASN.1 Types and Values

ASN.1 (Abstract Syntax Notation One) provides a comprehensive set of data types and values to represent various structures in a standardized way. These data types ensure effective communication across different platforms. Here's a breakdown of some common ASN.1 types and values:


An INTEGER type represents integer values (both positive and negative). It can be of any size and is often used for numerical identifiers or counts.


age INTEGER ::= 30


The BOOLEAN type represents logical true or false values. It is typically used for flags and binary decisions.


isActive BOOLEAN ::= TRUE


An OCTET STRING holds a sequence of octets (bytes), commonly used for binary data like images, files, or cryptographic keys.


rawData OCTET STRING ::= 'E04FD020EA3A6910A2D808002B30309D'H


The NULL type signifies the absence of a value. Often used as a placeholder in optional fields.


nothing NULL ::= NULL


An OBJECT IDENTIFIER (OID) is a globally unique identifier used to reference specific standards, protocols, or objects.


myObjectIdentifier OBJECT IDENTIFIER ::= { iso member-body us(1) ansi-x9-57(100) }


It is similar to an INTEGER but constrained to a predefined list of values. The ENUMERATED type is useful for representing options or states.


status ENUMERATED { active(0), inactive(1), pending(2) }


This is a string type encoded using UTF-8. It is ideal for representing textual data containing special characters or non-Latin alphabets.


fullName UTF8String ::= "Alice Smith"


A SEQUENCE is a collection of different data fields, acting like a struct or record in programming. Fields can be mandatory or optional.


PersonRecord ::= SEQUENCE { name UTF8String, age INTEGER, address UTF8String OPTIONAL }


A SEQUENCE OF is a collection of elements of the same type, similar to an array.


PhoneNumbers ::= SEQUENCE OF UTF8String


This is like a SEQUENCE, but its fields do not need to appear in a particular order.


Identity SET { firstName UTF8String, lastName UTF8String }

ASN.1 Macros

In ASN.1, macros were introduced to simplify the specification of certain structures by defining reusable templates for data structures. Although macros have been largely replaced by other mechanisms in later revisions of ASN.1, understanding their historical use is important for working with older specifications.

Macros served a role similar to functions or templates in programming languages. They allowed users to define a reusable pattern that could be expanded with specific details wherever needed, thus reducing redundancy and simplifying complex definitions.

Macro Syntax

A macro is defined using the following general structure:

MyMacro MACRO ::= BEGIN -- Macro definition content goes here END

Example of a Macro

A simple example could involve defining a macro that creates a TaggedType:


Here, TYPE NOTATION and VALUE NOTATION are placeholders that are filled in when the macro is used.

With the evolution of ASN.1, macros have been replaced by more powerful and flexible constructs like parameterized types and information object classes. Parameterized types provide a way to specify templates that can be reused with different data types, while information object classes allow constraints and relationships to be specified more explicitly.

ASN.1 Encoding Rules

ASN.1 Encoding Rules define how data structures described in ASN.1 should be serialized and deserialized into a binary format suitable for transmission or storage. Each encoding rule provides different levels of efficiency and applicability based on specific requirements like size, processing speed, or strictness.

Here is a list and explanation of some common encoding rules in ASN.1:

  • Basic Encoding Rules (BER). BER is a flexible encoding rule that uses a type-length-value (TLV) format for encoding. Each element begins with an identifier to indicate its type, followed by the length of the value, and finally, the value itself. BER allows indefinite-length encoding, which provides flexibility but can result in larger encoded data compared to other rules.
  • Distinguished Encoding Rules (DER). DER is a subset of BER that ensures consistent encoding by enforcing specific rules, like using the smallest possible length encoding. It provides unambiguous binary representations of data structures. DER is widely used in security protocols and digital certificates because it guarantees that the same ASN.1 structure always encodes identically.
  • Canonical Encoding Rules (CER). CER is also a subset of BER designed for unambiguous encoding. It is similar to DER but allows for indefinite-length encoding of some types, which is useful for large data sets. CER is ideal for streaming applications where data structures might not fit in a predefined length.
  • Packed Encoding Rules (PER). PER is designed to be highly efficient by removing unnecessary metadata. It optimizes encoding by using the minimum number of bits needed for each field, often based on predefined ranges or constraints. PER produces significantly smaller data sizes compared to BER, DER, and CER, making it suitable for bandwidth-sensitive applications like mobile communications.
  • XML Encoding Rules (XER). XER maps ASN.1 structures to an XML representation, making it human-readable. It aims to improve interoperability by leveraging the popularity of XML for data exchange. XER is particularly useful where data needs to be reviewed or modified by humans or integrated into existing XML-based workflows.

JSON Encoding Rules (JER). JER maps ASN.1 structures to a JSON representation, making them readable and usable in web applications. It leverages JSON's popularity in web services. JER is useful for modern web-based systems that rely on JSON for data interchange and storage.

Anastazija is an experienced content writer with knowledge and passion for cloud computing, information technology, and online security. At phoenixNAP, she focuses on answering burning questions about ensuring data robustness and security for all participants in the digital landscape.