1001Ferramentas
🔤Converters

Base91 Encoder/Decoder

Encode and decode text in Base91, a more compact format than Base64 because it packs more data into each printable ASCII character.

Base91

basE91: squeezing more data into printable text

basE91 uses 91 of the printable ASCII characters, against base64's 64, and with that the growth drops from 33% to roughly 23%. Its mechanics differ from the other bases: instead of grouping into fixed blocks, it accumulates bits in a register and emits two characters whenever 13 or 14 bits are available — the count varying according to whether the value fits in 13 bits.

Type the text and get the encoding. That 13-or-14-bit variation is what makes the format more efficient than base85, and also what makes it harder to implement correctly: an error in the threshold produces plausible, undecodable output. The implementation was checked against known vectors — "test" encodes to fPNKd and "a" to GB.

The price of that efficiency is the alphabet, which includes double quotes, the dollar sign, the backtick and other characters needing escapes in nearly every context: inside code strings, in URLs, in XML, in CSV. That is why basE91 shows up rarely in practice despite being measurably smaller than base64 — the saving seldom justifies the extra care in transport.

Frequently asked questions

Why 13 bits sometimes and 14 others?
Because the algorithm checks whether the low 13 bits form a value small enough to fit a character pair. When they do, it consumes 13; when they do not, 14. That adaptive decision is what squeezes the result below what base85 manages.
Is it safe in a URL?
Not without escaping. The alphabet includes the ampersand, question mark, hash, plus sign and others with meaning in a URL. Escaping cancels much of the size saving — for URLs, base64url or base58 are better choices.
Is it worth it over base64?
Only when size genuinely matters and transport is controlled at both ends, as in a private binary protocol. In any situation where the text passes through systems you do not control, ten percentage points of saving do not pay for the risk of a character being altered along the way.

Related Tools