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.
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.
| # | Path | Offset | Tag | Class | P/C | Tag Number | Length | Value / Children | Encoded 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.
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?
What is BER-TLV?
How do I decode TLV hex?
How do I know whether a BER tag is constructed?
How are BER tag classes identified?
How do multi-byte BER tags work?
What is BER short-form length?
What does BER length 81 mean?
What does BER length 82 mean?
What does BER length 80 mean?
Can a primitive BER value have indefinite length?
What is the BER End-of-Contents marker?
What does tag 30 mean?
What does tag 9F02 mean structurally?
Can a BER-TLV contain nested TLVs?
Does BER-TLV always use one-byte lengths?
Is BER the same as DER?
Can this decoder identify proprietary tag names?
Can I decode several TLVs in one input?
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.