Encoding ยท Developer Guide
Base64 Encoding and Decoding Explained
Base64 is useful when a protocol expects text but your data is bytes. Start by identifying the byte encoding and Base64 variant, then decode with a tool that matches both.
What is Base64?
Base64 represents bytes using a limited text alphabet. Standard Base64 includes + and /, with = used for padding. Base64URL uses different characters; a JWT segment and a standard Base64 string are not interchangeable without accounting for that variant.
How the text tools work
Small Tools first encodes input text as UTF-8 bytes, then produces standard Base64. Decoding reverses the process and requires the decoded bytes to be valid UTF-8. This supports Unicode text, but it is not a binary file viewer.
Base64 text is usually larger than the source bytes, roughly four output characters for every three bytes before transport overhead. Use it because the protocol requires it, not as compression.
Example: verify a text round trip
Encode Hello, copy the exact result, and decode it. Repeat with a Unicode sample such as Hello ๐ to confirm that a downstream system uses UTF-8 too. A round trip proves the representation survived; it does not prove authenticity.
Hello
SGVsbG8=
HelloCommon mistakes
- Treating Base64 as encryption: anyone who obtains the text can decode it.
- Decoding an entire JWT including dots: use the JWT-specific tool for segments and Base64URL.
- Expecting an image or archive to appear as readable text: valid Base64 can decode to non-UTF-8 bytes and this text decoder will reject it.
- Editing padding or replacing + with spaces during form transport: preserve the value using the transport's required encoding.
Practical use cases and security
For a Basic Authentication header, use the dedicated builder so the username, separator, password, and byte encoding are handled together. Send credentials only over HTTPS; Base64 offers no secrecy.
For an integration mismatch, compare the original bytes, variant, padding expectations, and character encoding on both sides. The linked text tools process locally. Redact secrets before storing the output in documentation or support tickets.
Run it yourself
Every result in the block below comes from one Node.js v26.12.1 run. Small Tools Base64 Encoder gives SGVsbG8g8J+MjQ== for Hello ๐, and Base64 Decoder returns Hello ๐. The decoder also returns รฉ for w6k= (the UTF-8 bytes of รฉ) and Hello for SGVsbG8 without padding.
It rejects two kinds of input that other tools accept. 6Q== is the single Latin-1 byte for รฉ, so the decoder reports that the data was not valid UTF-8. The Base64URL value -_-_ is reported as an invalid character, because Base64URL uses - and _ in place of + and /. Convert those two characters first, or use JWT Decoder for token segments.
Buffer.from("Hello ๐", "utf8").toString("base64")
// SGVsbG8g8J+MjQ==
btoa("Hello")
// SGVsbG8=
btoa("รฉ") // one Latin-1 byte
// 6Q==
Buffer.from("รฉ", "utf8").toString("base64") // two UTF-8 bytes
// w6k=
btoa("๐")
// InvalidCharacterError: Invalid character
Buffer.from([0xfb, 0xff, 0xbf]).toString("base64")
// +/+/
Buffer.from([0xfb, 0xff, 0xbf]).toString("base64url")
// -_-_
[3, 4, 5, 6].map((n) => Buffer.alloc(n).toString("base64").length).join(", ")
// 4, 8, 8, 8What this guide does not verify
- Binary files and very large inputs. The Small Tools pages handle text, not file contents.
- Line-wrapped Base64 as used in email. RFC 2045 requires lines of no more than 76 characters, and libraries differ in whether they accept line breaks inside a value.
- How other libraries treat missing padding or the URL-safe alphabet. The examples were run in Node.js only, and browsers and other languages can differ.
- Whether decoded bytes mean anything. Base64 says nothing about what the data is or who produced it.
Frequently asked questions
Why does btoa fail on an emoji? btoa accepts only characters that fit in one byte, so btoa("๐") throws InvalidCharacterError. Encode the text as UTF-8 first, which is what Small Tools does, and then apply Base64.
Why do two Base64 strings for รฉ differ? 6Q== encodes the Latin-1 byte and w6k= encodes the UTF-8 bytes. Both decode correctly only when the receiver uses the same text encoding as the sender.
Why is a Base64URL value rejected by Base64 Decoder? Base64URL replaces + with - and / with _, and often omits padding. The standard decoder accepts only the standard alphabet.
Related tools
- Base64 Encoder โ Encode text as Base64 with Unicode support.
- Base64 Decoder โ Decode Base64 text safely in your browser.
- JWT Decoder โ Decode a JWT header and payload without verifying its signature.
- Basic Auth Header Generator โ Create an HTTP Basic Authorization header locally from a username and password.