Bencode Encoder/Decoder
Decode bencode (the encoding used by BitTorrent .torrent files) into JSON, or encode JSON into bencode — with a torrent-info summary when decoding a torrent file's dictionary.
Input
Output
| Property | Value |
|---|---|
| No data yet | |
Guides
What is bencode?
Bencode ("B-encode") is the data serialization format used by BitTorrent — it's how .torrent files and tracker responses encode integers, byte strings, lists, and dictionaries. It's simpler than JSON (no whitespace, no floats, dictionary keys must be strings and are sorted) but serves the same purpose: a compact, unambiguous way to represent structured data.
How this tool works
Switch between two modes:
- Decode (Bencode → JSON) — paste raw bencode text (or upload a
.torrentfile) and get back readable JSON. Binary data that isn't valid UTF-8 text is represented as ahex:-prefixed hex string, since JSON can't hold raw bytes. - Encode (JSON → Bencode) — paste JSON and get back its bencode representation. Dictionary keys are sorted alphabetically, matching the canonical bencode encoding rule.
If the decoded data looks like a torrent file (has an announce URL, an info dictionary, etc.), a Torrent Info table summarizes the tracker, name, piece length, file list, and total size.
Bencode's four types
- Integers:
i42e→42(arbitrarily large — this tool usesBigIntinternally so oversized integers don't silently lose precision, falling back to a string for values beyondNumber.MAX_SAFE_INTEGER) - Byte strings:
5:hello→"hello"(length-prefixed, no quotes) - Lists:
l4:spam4:eggse→["spam", "eggs"] - Dictionaries:
d3:cow3:mooe→{"cow": "moo"}(keys must be strings, sorted when encoding)
Common uses
- Inspecting the contents of a
.torrentfile without a BitTorrent client - Debugging a bencode-producing or bencode-consuming service
- Converting structured data to bencode for a BitTorrent-adjacent protocol
- Learning the bencode format by seeing it side-by-side with JSON
Privacy
This tool runs entirely in your browser. Your data is never uploaded to a server.