What Base64 represents in bytes, text, and transport
Base64 is a reversible byte-to-text encoding: every three raw bytes become four printable ASCII characters from a 64-symbol alphabet. It is specified in RFC 4648 and shows up in HTTP Basic Authorization, PEM certificates, many JSON fields, and data: URLs—not because it hides data, but because it moves binary or non-ASCII bytes through channels that only tolerate ASCII text safely.
This page implements the standard alphabet A–Z, a–z, 0–9, +, / with = padding for the common “encode UTF-8 text” and “decode Base64 back to UTF-8 string” path your browser and Node use for string payloads. It is not a substitute for encrypting secrets; pair TLS in transit with real cryptography when confidentiality matters. For turning image or file bytes into Base64 or Data URLs, use image to Base64 and to reverse a visual payload use Base64 to image.
Confusion often comes from mixing roles: hex shows each byte as two nibbles; Base64 packs bits more densely; URL percent-encoding escapes reserved characters in URLs and is unrelated to the Base64 alphabet. JWT header and payload segments are Base64url (- / _, often no padding), which differs from the +/ form you paste here unless you normalize.
How Base64 relates to bits, padding, and UTF-8
Why three bytes become four characters and how the 6-bit groups line up
- Each input byte is eight bits; four Base64 output characters carry six bits each, so 4×6 = 24 bits holds exactly three bytes.
- The encoder concatenates those bits, reads successive 6-bit indexes, and picks the symbol from the 64-character table.
- Decoding inverts the process: four symbols yield 24 bits, split back into three bytes in order.
What the trailing equals signs do when the byte count is not a multiple of three
- If one byte remains after full triplets, the second quartet is padded with zeros and two = characters finish the block.
- If two bytes remain, one = is emitted so the total output length stays a multiple of four characters.
- Strict decoders reject wrong padding length; some runtimes tolerate missing padding—this page expects valid RFC-style padding for decode.
Why text encoding must be UTF-8 before Base64 and what happens on decode
- JavaScript string Base64 uses UTF-8 bytes as the input octet stream, the same as btoa with binary strings built from those bytes.
- If upstream produced Base64 from UTF-16 or Latin-1 without agreement, decoding here can show mojibake even when the Base64 string is valid.
- Emoji and scripts outside the BMP still encode as multi-byte UTF-8 sequences before Base64; the character count of the string is not the byte count.
How Data URLs differ from raw Base64 payloads in HTML and APIs
- A Data URL has the shape data:[mediatype][;base64], followed by the payload—browsers need the prefix to interpret inline images or downloads.
- REST or GraphQL fields often store only the payload and send the MIME type in another property; do not paste the entire Data URL into this decoder unless you strip the prefix first.
- The ;base64 marker distinguishes the segment from quoted-printable or percent-encoded forms in the same family of “ASCII armor”.
Where URL-safe Base64 and the standard +/ alphabet disagree
- URL-safe variants swap +→- and /→_ and may omit = so query strings stay unescaped.
- JWT uses Base64url for header and payload pieces; transform characters before comparing with tools that only accept +/.
- This codec follows standard Base64; translate symbols manually when an API contract specifies URL-safe form.
Where teams bump into Base64 beside “encode this string”
Authorization headers and opaque tokens in logs
Basic Auth concatenates user:password, Base64-encodes the UTF-8 bytes, and prefixes Basic —the string is still reversible by anyone who can read the header. Opaque bearer tokens are often random bytes Base64-encoded for display; treat them like secrets in logs regardless of encoding.
JWT segments versus the HMAC or RSA signature
The header and payload are JSON objects Base64url-encoded for transport; they are not encrypted. Integrity comes from the third segment and the shared or public key—verify signatures in your stack, not by eyeballing Base64 text.
Embedding small assets in HTML or CSS
Data URLs increase markup size roughly four-thirds over raw bytes but avoid an extra HTTP request for tiny icons. Large media still belongs in binary files or CDNs; compare byte cost with image to Base64 when sizing bundles.