Base122 Encoder/Decoder

Experimental ultra-dense 7-bit encoding for HTML and JS embedding

Ad placeholder (leaderboard)

Base122 is an experimental binary-to-text encoding that squeezes data into UTF-8 strings more tightly than Base64. It was designed for embedding binary blobs directly inside HTML or JavaScript source, where the usual Base64 data URI wastes about a third of the bytes. This tool encodes UTF-8 text to Base122 and decodes it back, entirely in your browser.

How it works

Base122 treats the input as a continuous bit stream and reads it 7 bits at a time. Each 7-bit chunk usually maps directly to a single byte in the 0-127 range, which is one UTF-8 byte. The trick is the six values that are dangerous inside string literals: null, \n, \r, ", & and \. When a 7-bit chunk equals one of those, Base122 emits a two-byte sequence that stores which illegal value it was plus the next 7 bits of data, so the stream never contains a raw unsafe byte. A trailing “shortened” form is used when an escaped chunk is the very last piece of data.

Because most chunks cost one byte and only the six special cases cost two, the output averages roughly 1.14 bytes per 7 input bits — denser than Base64’s 1.33 bytes per 6 bits.

Tips and notes

Use Base122 only when you control both ends. It is not a standard like Base64, so other tools will not decode it. A good real use is inlining a small font, image or WASM payload in a single-file web page where every kilobyte counts. For email or URLs, prefer Quoted-Printable or URL-safe Base64 instead, since those target those specific transports.

Ad placeholder (rectangle)