BER Length Visualizer
Encode any non-negative integer length to BER octets, or decode a hex length back to its value. Covers short-form, long-form (1..126 octets), and indefinite-form (0x80) encodings.
How to use this tool
What it does
Encodes and decodes BER-TLV length fields, including short form and multi-byte long form (X.690).
When to use it
Use it when hand-reading or building a TLV and you need to interpret a length prefix that runs past one byte.
Worked example
Decode 82 01 2C to the length 300, or encode 300 back to those bytes.
Decode
Result
About BER length
BER (X.690 §8.1.3) defines three length forms. Short-form: a single byte ≤ 0x7F. Long-form: first byte 0x81..0xFE encoding the count of subsequent length octets, followed by big-endian length. Indefinite-form: 0x80 (BER only — DER forbids it). DGI long-form (used in some EMV personalisation specs) is a stricter variant: always FF || 2-byte BE length, even for small values.
Frequently asked questions
How does BER short-form length work?
When the length byte is 0x7F or lower it is the length itself, encoding values from 0 to 127 in a single octet.
How does long-form length work?
A length byte above 0x80 does not hold the length: its low seven bits give the number of following octets that do. 0x82 means the next two bytes are the length, big-endian.
What is indefinite-form length?
0x80 signals that the content runs until an end-of-contents marker of two zero bytes. It is legal in BER but forbidden in DER, so it should never appear in a signed structure.
Why does 0x81 appear before a small length?
Long form was used where short form would have done. DER forbids this — lengths must use the shortest possible encoding — so it usually indicates a BER encoder or a hand-built blob.
Does anything I paste leave my browser?
Nothing. The tool is entirely client-side: the page ships a static script, does no network calls, and never transmits what you paste. You can confirm it by opening the network tab, or by loading the page and then going offline.