TLV Binary Structure Decoder

TLV / BER-TLV Decoder

Use this TLV / BER-TLV Decoder to inspect hexadecimal Tag-Length-Value data. Decode single-byte and multi-byte tags, BER tag class, primitive or constructed status, short and long-form lengths, nested TLVs, value bytes and constructed indefinite-length BER structures.

✓ Multi-Byte Tags ✓ BER Length Decoder ✓ Nested TLV ✓ Tag Class ✓ Indefinite Length
T/L/V
Decode BER-TLV Bytes
● Ready
Enter hexadecimal bytes separated by spaces, commas, colons or hyphens. Continuous hex and 0x prefixes are accepted.
Important: this is a structural BER-TLV decoder. A tag such as 9F02 can be decoded into its BER class, primitive/constructed bit and tag number without assuming a particular payment, smart-card or proprietary data dictionary. Application-specific tag names and value semantics require the relevant protocol specification.
TLV / BER-TLV Result Decoded
Decoded Structure
Input Bytes
TLV Items
Primitive Items
Constructed Items
Max Depth
Multi-Byte Tags
Long Lengths
Indefinite Items
# Path Offset Tag Class P/C Tag Number Length Value / Children Encoded Bytes
Tag / Length / Value Breakdown -
Normalized TLV Bytes
-

What Is a TLV Decoder?

A TLV decoder separates binary data into three logical components: Tag, Length and Value. The tag identifies the type or meaning of the value, the length identifies how many content bytes belong to that item, and the value contains the actual payload or nested TLVs.

BER-TLV is based on the ASN.1 Basic Encoding Rules identifier and length encoding. BER supports multiple tag classes, primitive and constructed values, large tag numbers, short and long-form lengths and constructed indefinite-length encodings. :contentReference[oaicite:1]{index=1}

Tag-Length-Value Structure

TLV = Tag + Length + Value

For a simple example:

5A 02 12 34 Tag: 5A Length: 02 Value: 12 34

The length is two, so exactly two bytes belong to the value.

BER Identifier Octet

The first BER tag byte contains three fields:

Bits 8–7: Class Bit 6: Primitive / Constructed Bits 5–1: Tag number or high-tag-number marker

If bits 5 through 1 equal 11111, the actual tag number continues in subsequent base-128 tag-number octets. :contentReference[oaicite:2]{index=2}

BER Tag Classes

Class Bits Class Purpose
00 Universal ASN.1-defined universal types
01 Application Application-specific type
10 Context-Specific Meaning depends on surrounding ASN.1 context
11 Private Privately defined use

Primitive vs Constructed TLV

Bit 6 of the first BER identifier byte tells whether the contents are primitive or constructed. X.690 specifies zero for primitive and one for constructed encoding. :contentReference[oaicite:3]{index=3}

Primitive

The value is treated as content bytes. Its application meaning depends on the tag and protocol.

Constructed

The contents consist of additional BER-encoded data items and can therefore be decoded recursively.

Example: ASN.1 Sequence

Consider:

30 0A 02 01 01 04 05 68 65 6C 6C 6F

The first byte 30 is a universal constructed tag number 16, commonly the ASN.1 SEQUENCE tag.

30 → Universal → Constructed → Tag number 16 0A → 10 content bytes Inside: 02 01 01 and: 04 05 68 65 6C 6C 6F

BER Short-Form Length

When bit 8 of the first length octet is zero, the remaining seven bits directly contain the content length.

05 → 5 content bytes 7F → 127 content bytes

BER short-form length is available for lengths from zero through 127. :contentReference[oaicite:4]{index=4}

BER Long-Form Length

For longer definite lengths, bit 8 of the first length byte is one. The lower seven bits state how many following octets contain the actual length.

81 80 81 → one following length octet 80 → 128 bytes Length = 128

Another example:

82 01 00 82 → two following length octets 01 00 → 256 Length = 256 bytes

X.690 defines this short/long definite length distinction and states that FF is not used as a valid initial long-form length octet. :contentReference[oaicite:5]{index=5}

BER Indefinite Length

The special length octet:

80

means the contents have indefinite length. The constructed content continues until an End-of-Contents marker:

00 00

BER permits the indefinite form for constructed encodings, while primitive encoding uses the definite form. :contentReference[oaicite:6]{index=6}

Indefinite-Length Example

30 80 02 01 05 00 00

The decoding is:

30 → constructed universal tag 16 80 → indefinite length 02 01 05 → nested integer TLV 00 00 → End-of-Contents

Multi-Byte BER Tags

If the low five bits of the first identifier octet are all ones, the tag number is encoded in following octets. Each subsequent octet contributes seven tag-number bits, and bit 8 indicates whether another tag-number octet follows. :contentReference[oaicite:7]{index=7}

9F 02 9F → Context-Specific → Primitive → high-tag-number form 02 → final tag-number group Tag number = 2 Encoded tag bytes = 9F02

Example: Decode 9F 02 06 …

9F 02 06 00 00 00 00 01 00

Structurally this means:

Tag: 9F 02 Class: Context-Specific Encoding: Primitive Tag Number: 2 Length: 6 bytes Value: 00 00 00 00 01 00

The decoder does not automatically label the value with an EMV or other industry-specific meaning because BER-TLV syntax alone does not establish the application data dictionary.

Nested Constructed TLVs

A constructed TLV may contain one or more complete child TLVs. This tool recursively parses those children and displays their hierarchy using paths such as:

$ $[0] $[1] $[1][0]

That makes it easier to inspect deeply nested ASN.1, smart-card or proprietary BER structures.

One TLV vs TLV Sequence

Some buffers contain exactly one outer BER-TLV object. Others contain several top-level TLVs placed one after another.

One Complete TLV

The decoder requires the first TLV to consume the complete byte stream. Trailing bytes are treated as an error.

Sequence of TLVs

The decoder continues parsing top-level TLVs until the complete byte stream has been consumed.

BER-TLV Value Interpretation

A structural TLV decoder can reliably determine the encoded tag, content length and raw value boundaries. It cannot always determine the application meaning of primitive value bytes.

For example, the same primitive bytes could represent an integer, identifier, BCD value, application-specific number or opaque binary data depending on the protocol definition. This calculator therefore keeps the hexadecimal value as the source of truth and only adds a readable text preview when appropriate.

BER-TLV vs Simple One-Byte TLV

Some protocols use a simpler TLV format where the tag and length always have fixed widths. BER-TLV is more flexible: tags can contain multiple identifier octets and lengths can use short, long or constructed indefinite forms.

This calculator specifically understands the BER identifier and BER length rules instead of assuming that every TLV consists of exactly one tag byte and one length byte.

BER, DER and CER

BER is the broad ASN.1 basic encoding rule set. DER and CER apply additional canonical restrictions. ITU-T X.690 defines all three; among their major differences, DER uses definite lengths while CER makes canonical use of indefinite-length constructed forms in applicable cases. :contentReference[oaicite:8]{index=8}

This page is a BER-TLV structural decoder. It does not claim that every structurally valid BER encoding is also valid DER or canonical CER.

Common BER-TLV Errors

Truncated Tag

A high-tag-number identifier says another tag octet follows, but the input ends.

Truncated Length

A long-form length announces additional length octets that are missing.

Length Exceeds Input

The declared value length is larger than the bytes remaining in the buffer.

Primitive Indefinite Length

Indefinite length is not valid for a primitive BER encoding.

Missing End-of-Contents

An indefinite constructed object reaches the end of input before 00 00 appears.

Unexpected EOC

00 00 appears where an ordinary definite TLV item is expected.

Typical Uses for a BER-TLV Decoder

ASN.1 Debugging

Inspect identifier, length and nested content structure from BER-encoded data.

Smart Cards

Examine BER-TLV records without assuming unsupported application semantics.

Protocol Analysis

Verify tag boundaries and content lengths in binary messages.

Embedded Development

Check TLV serializers and parsers used by firmware and communication protocols.

TLV / BER-TLV Decoder FAQs

What does TLV stand for?
TLV stands for Tag-Length-Value.
What is BER-TLV?
BER-TLV uses ASN.1 Basic Encoding Rules-style identifier and length encoding to represent tagged values, including multi-byte tags and constructed content.
How do I decode TLV hex?
Decode the tag first, then decode the length field, and finally read exactly the declared number of value bytes. If the tag is constructed, its value can contain nested TLVs.
How do I know whether a BER tag is constructed?
Bit 6 of the first identifier octet is one for constructed encoding and zero for primitive encoding.
How are BER tag classes identified?
The top two bits of the first identifier byte identify Universal, Application, Context-Specific or Private class.
How do multi-byte BER tags work?
When the first tag byte’s low five bits equal 31, following octets encode the tag number in seven-bit base-128 groups.
What is BER short-form length?
A one-byte length from 0 through 127 where the most significant bit is zero.
What does BER length 81 mean?
81 means one additional octet contains the actual definite content length. For example, 81 80 represents a length of 128 bytes.
What does BER length 82 mean?
82 means two following octets contain the content length in big-endian order. For example, 82 01 00 represents 256 bytes.
What does BER length 80 mean?
80 is the indefinite-length form. It is used with constructed encodings whose contents terminate with the End-of-Contents marker 00 00.
Can a primitive BER value have indefinite length?
No. BER requires primitive encoding to use a definite form of length.
What is the BER End-of-Contents marker?
It is 00 00 and terminates an indefinite-length constructed value.
What does tag 30 mean?
Structurally, 30 is Universal class, Constructed, tag number 16. In ASN.1 universal tagging, tag number 16 is SEQUENCE.
What does tag 9F02 mean structurally?
It is a multi-byte Context-Specific primitive BER tag whose decoded tag number is 2. Application-specific meaning depends on the protocol using that tag.
Can a BER-TLV contain nested TLVs?
Yes. Constructed values contain encoded child items and can be nested recursively.
Does BER-TLV always use one-byte lengths?
No. BER supports short-form length, multi-octet long-form length and indefinite length for constructed encodings.
Is BER the same as DER?
No. DER is a restricted canonical subset of BER and requires definite-length encoding.
Can this decoder identify proprietary tag names?
Not from BER syntax alone. Tag names and value semantics require the relevant application or industry specification.
Can I decode several TLVs in one input?
Yes. Select Sequence of TLVs to decode consecutive top-level TLV objects.

Decode BER Tag, Length and Value Structures

Paste hexadecimal TLV data to inspect tag bytes, BER class, tag numbers, primitive or constructed encoding, definite or indefinite length fields, nested children and raw value bytes.

Scroll to Top