Base64, Hex, percent encoding and Base85: choose by transport

Compare byte overhead, escaping and interoperability without confusing text encoding with numerical radix conversion.

An encoding is useful only if both ends agree on it. The smallest representation is not necessarily the best choice when the receiver needs a familiar alphabet, the payload must be typed by a person, or the surrounding syntax treats certain characters specially. Begin with the receiving protocol.

Hex is verbose but easy to inspect

Hexadecimal writes each byte as two digits. The byte sequence FF 00 41 becomes ff0041. Every pair has a visible byte boundary, which helps when inspecting file signatures, checksums and protocol packets. It doubles the character count, but its small alphabet usually fits easily into logs and debugging tools.

Base64 balances size and interoperability

Base64 represents three bytes with four characters. It is a common fit for binary fields inside text-based formats. Standard Base64 includes plus and slash; Base64URL replaces those characters when a protocol needs a different alphabet. Padding and whitespace rules still need agreement. Neither form tells the receiver whether the decoded bytes are text, an image or compressed content.

Percent encoding belongs to URL components

Percent encoding writes an escaped byte as %HH. It is not simply a bulk substitute for Base64. The component determines which characters must be escaped, and text should first be encoded as UTF-8. A slash may separate path segments while a question mark starts a query; treating the whole URL as one opaque component changes its meaning.

console.log(encodeURIComponent('a+b / 中文'));
// a%2Bb%20%2F%20%E4%B8%AD%E6%96%87

Base85 needs an exact variant

Many Base85 schemes represent four bytes with five characters, but their alphabets, delimiters and special cases differ. ASCII85 and Z85 cannot be assumed interchangeable. Z85 also imposes block-size requirements. A high-density alphabet may contain punctuation that must be escaped again in the surrounding format, reducing the apparent benefit.

Do not confuse these byte encodings with converting the integer 255 between number bases. A file can begin with zero bytes, while an integer representation may discard those leading zeros. A reversible file codec must define how length and leading zeros are preserved.

Use Hex for byte inspection, the specified Base64 variant for interoperable binary transport, URL component encoding for URLs, and a specialized scheme only when both parties implement the same contract. Compare end-to-end size after escaping and compression. RFC 4648 defines the standard Base16, Base32 and Base64 families, including their distinct alphabets.