wire / encoding / base64

Base64 (RFC 4648 §4)

Base64 maps every 3 input bytes to 4 ASCII characters drawn from a 64-symbol alphabet (A–Z, a–z, 0–9, '+', '/'), padding the final group with '=' so the output length is always a multiple of 4. It is the canonical binary-to-text encoding for MIME, data: URLs, PEM, HTTP Basic auth, and JWT headers/payloads (which use the URL-safe variant).

encoding kind encoding status standard verification verified tier A encoding@1

aka: base-64 · RFC 4648 base64 · standard base64 · MIME base64

test vectors

RFC4648 · alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/

inputoutputnote
utf8 ascii RFC 4648 §10 test vector: BASE64("") = "".
f utf8 Zg== ascii RFC 4648 §10 test vector: BASE64("f") = "Zg==" (1 byte -> 2 chars + '==').
fo utf8 Zm8= ascii RFC 4648 §10 test vector: BASE64("fo") = "Zm8=" (2 bytes -> 3 chars + '=').
foo utf8 Zm9v ascii RFC 4648 §10 test vector: BASE64("foo") = "Zm9v" (3 bytes -> 4 chars, no padding).
foob utf8 Zm9vYg== ascii RFC 4648 §10 test vector: BASE64("foob") = "Zm9vYg==".
fooba utf8 Zm9vYmE= ascii RFC 4648 §10 test vector: BASE64("fooba") = "Zm9vYmE=".
foobar utf8 Zm9vYmFy ascii RFC 4648 §10 test vector: BASE64("foobar") = "Zm9vYmFy" (6 bytes -> 8 chars, no padding).
Zm9vYmFy ascii foobar utf8 Round-trip: BASE64-decode("Zm9vYmFy") = "foobar".

provenance

see also

agent: curl -H 'accept: application/json' wire.phall.io/encoding/base64 or /encoding/base64.json