EMV TLV Builder & Decoder

Build a TLV hex string from tag/value pairs (left) and decode TLV into EMV tags (right).

Build TLV

Enter one tag per line. Values should be hex (no spaces). You can use either = or whitespace.


Built TLV output

Length encoding follows EMV BER‑TLV rules (short form up to 127 bytes; long form uses 81/82).

How encoding works (mock)

function buildTLV(pairs):
  tlv = ""
  for each (tag, valueHex) in pairs:
    lenBytes = (valueHex.length / 2)
    L = encodeLength(lenBytes)   // 0..127 => 1 byte, else 81/82 + length
    tlv += tag + L + valueHex
  return tlv

EMV TLV encoding (builder)

EMV data elements are commonly represented as TLV (Tag‑Length‑Value). To encode TLV, you concatenate the tag bytes, the encoded length, then the value bytes (usually represented as hex in logs and ISO8583 DE55).

1) Tag (T)

  • Tags can be 1–3 bytes (e.g. 82, 5F2A, 9F33).
  • In this builder, you provide the tag as hex (no spaces).

2) Length (L)

  • Length is the number of bytes in the value (not hex characters).
  • Short form: 0..127 bytes → one length byte (e.g. 06).
  • Long form: if length ≥ 128, first byte indicates how many length bytes follow (e.g. 81 + 1 byte, 82 + 2 bytes).

3) Value (V)

  • Value is raw bytes. In hex form, it must be even-length.
  • Example: 9F0206 000000100100 → Tag 9F02, Length 06, Value 000000100100.
This page validates the TLV it builds by round‑tripping through the same decoder logic (parseTags) to catch length/value mistakes early.

Decode TLV

Paste TLV hex (e.g. DE55) and decode to tags.



Decoded tags

How decoding works (mock)

function parseTLV(tlvHex):
  while tlvHex not empty:
    tag = readKnownTagPrefix(tlvHex)  // 1..3 bytes from known list
    len = readLength(tlvHex)          // supports 81/82 long form
    value = read(len bytes)
    emit(tag, value)

EMV TLV decoding (parser)

To decode EMV TLV, you read the stream from left to right and repeatedly extract a tag, then its length, then exactly that many value bytes.

Step A: Read the tag (T)

  • Tags have variable size. Many EMV tags start with 9F (two-byte tags), but not all.
  • This decoder uses a known-tag list to determine whether the next 1, 2, or 3 bytes form a valid tag.

Step B: Read the length (L)

  • If the first length byte is < 0x80, that value is the length in bytes.
  • If the first length byte has the high bit set (e.g. 81, 82), then the lower bits tell how many bytes follow to represent the length.

Step C: Read the value (V)

  • Read exactly L bytes as the value.
  • Some tags are constructed (contain nested TLVs). In our util, tags starting with FF trigger a recursive parse.
If you see missing tags or misaligned values, the most common cause is a wrong length (a single byte off will break everything after it).
  Related

Recent Articles on Iso8583