Bencode converter

What is a Bencode Converter?

Bencode (pronounced B-encode) is the serialization format used by BitTorrent for .torrent metainfo files and tracker responses. It supports only four types: byte strings, integers, lists and dictionaries. This converter turns bencoded data into readable JSON so you can inspect it, and encodes JSON back into valid bencode.

How to use it

  1. Paste bencoded text or load its content to decode it to JSON.
  2. Or paste JSON to encode it as bencode.
  3. Copy the output.

The format in one minute

  • String: length, colon, bytes. 4:spam is the string spam.
  • Integer: i, digits, e. i42e is 42.
  • List: l, items, e. l4:spami42ee is the list spam, 42.
  • Dictionary: d, key-value pairs, e, with keys sorted. d3:cow3:moo4:spam4:eggse is the object cow: moo, spam: eggs.

What is inside a .torrent file

The top-level dictionary usually contains announce (tracker URL), optional announce-list, creation date and an info dictionary with the name, piece length, pieces (concatenated SHA-1 hashes) and either length or a files list. The torrent's info-hash is the SHA-1 of the bencoded info dictionary, which is why dictionary keys must be sorted: any change in encoding changes the hash.

Notes

The pieces field is binary, so it may show as unreadable characters or hex. Bencode has no floats or booleans; encode them as integers or strings.

Frequently Asked Questions

What is bencode used for?

It is the format of BitTorrent .torrent files and tracker responses.

Why must dictionary keys be sorted?

The torrent info-hash is computed from the encoded info dictionary. Sorting guarantees that every client produces exactly the same bytes and therefore the same hash.

Why does the pieces field look like garbage?

It contains raw 20-byte SHA-1 hashes, which are binary data rather than text.

Does bencode support floating-point numbers?

No. It only supports integers, byte strings, lists and dictionaries.