Bencode Decoder — BitTorrent Bencode to JSON
A free bencode decoder online: paste bencoded data and read it as JSON instantly. This bencode to JSON converter decodes live as you type — with strict validation that pinpoints errors by byte position, a type-annotated tree view, flexible byte-string rendering (UTF-8, hex, or base64), and safe handling of integers beyond 253. No sign-up, no server: 100% in your browser.
Need to go the other way? Our bencode encoder converts JSON into bencode. This page is decode-only by design.
Decode bencode to JSON
Type or paste bencoded text — or load a .torrent file for binary-safe decoding. Decoding is live; malformed input is rejected with the exact byte offset.
Bencode format in 60 seconds
Bencode is the encoding defined by BEP 3 for the BitTorrent protocol. It has exactly four types — reading them is all this decoder does:
| Type | Syntax | Decodes to |
|---|---|---|
| Integer | i<n>e | i42e → 42 (arbitrary precision) |
| Byte string | <len>:<data> | 4:spam → "spam" (len = UTF-8 bytes) |
| List | l<items>e | l4:spami42ee → ["spam", 42] |
| Dictionary | d<pairs>e, keys sorted | d3:bar4:spam3:fooi42ee → {"bar": "spam", "foo": 42} |
| Input | Result |
|---|---|
i03e | Rejected: leading zeros are not allowed in integers |
i-0e | Rejected: negative zero is not allowed |
i42eXYZ | Rejected: trailing data after a complete value |
5:spam | Rejected: string declares 5 bytes but only 4 follow |
l4:spam | Rejected: unterminated list |
d1:bi1e1:ai2ee | Decoded with a warning: dictionary keys are not sorted |
"café" is 4 characters but 5 UTF-8 bytes, so it is written 5:café — try pasting that and see it decode back to "café".
pieces fields hold raw SHA-1 hashes, not text.
This decoder shows byte strings as UTF-8 text only when the bytes are valid UTF-8; otherwise it falls back to lowercase hex (switch to base64 any time with the options above).
Bencode decoder FAQ
What is bencode?
Bencode (pronounced "bee-encode") is the data encoding defined by BEP 3 for the BitTorrent protocol. It supports exactly four types: integers as i<n>e (for example, i42e), byte strings as <length>:<data> (for example, 4:spam), lists as l...e (for example, l4:spami42ee), and dictionaries as d...e with keys sorted in byte order (for example, d3:bar4:spam3:fooi42ee). A .torrent file is simply a bencoded dictionary.
How do I decode a bencode string with this tool?
Paste or type the bencoded text into the input box and the decoded JSON appears instantly — there is no button to press. Switch tabs to inspect the result as pretty JSON, as an annotated tree showing each value's bencode type, or as decode statistics. Choose how byte strings render (UTF-8 text, hex, or base64) and how integers render (auto, number, or string) with the options above the output. Use Copy for the JSON or Download to save it as a .json file.
What does the byte position in an error message mean?
Bencode is a byte-oriented format, so errors are reported as exact byte offsets — for example, "unexpected byte at offset 7" — counting from 0 at the start of your input. The error box also shows a context snippet with a caret pointing at the offending byte. The most common causes are a truncated paste, a wrong string length (4:spa declares 4 bytes but only 3 follow the colon), or stray characters after a complete value.
Why is the pieces field shown as hex instead of text?
Torrent piece hashes are raw binary bytes, not text, so they are not valid UTF-8. This decoder renders a byte string as UTF-8 text only when the bytes are valid UTF-8; otherwise it falls back to lowercase hex (or base64, if you pick that option). Use the byte-string options above the output to switch between Auto, UTF-8 text, Hex, and Base64 at any time — decoding is live.
Why do I get an "unsorted dictionary keys" warning?
BEP 3 requires dictionary keys to be sorted lexicographically by raw bytes — that ordering is what makes encodings canonical and torrent infohashes deterministic. This decoder still decodes the value, but warns you that the input is non-canonical. Note that duplicate keys are rejected outright, and so is any trailing data after a complete value. Strict encoders always emit sorted keys, so you will never see this warning on output from our Bencode Encoder.
What does the "trailing data" error mean?
It means a complete bencode value ended, but extra bytes followed — for example, i42eXYZ. A strict decoder accepts exactly one top-level value, and leftover bytes almost always indicate a truncated copy-paste or two values pasted together. Remove the extra bytes, or decode each value separately.
Can I decode a .torrent file with this tool?
Yes — click "Load .torrent file" and pick the file. It is read as raw bytes directly in your browser (binary-safe), so the 20-byte SHA-1 piece hashes decode correctly and show as hex. Your file never leaves your device: there is no upload, no account, and no server involved.
What happens to very large integers?
Bencode integers have arbitrary precision, but JavaScript numbers are exact only up to 2^53 − 1 (9007199254740991). In Auto mode, integers that fit become JSON numbers and larger ones become JSON strings, so no digit is ever lost — try decoding i1208925819614629174706176e. Choose "Always number" to force numbers (large values may round) or "Always string" to keep every integer as text.
What is the difference between this decoder and the Bencode Encoder?
They are one-way complements: this page only decodes bencode into JSON, while our Bencode Encoder (/tools/bencode-encoder/) only encodes JSON into bencode. Keeping them separate makes each tool's intent unambiguous — there is deliberately no encode mode on this page. If you need to go the other direction, use the encoder.
Is my data sent to a server when I use this decoder?
No. This bencode decoder runs entirely in your browser — the text or .torrent file you decode never leaves your device, there is no account or sign-up, and the page keeps working offline after it loads. That also means you can safely inspect private torrent metadata without privacy concerns.
Related tools
Free tool by NRTechStudio