How To Encode Text To Base64 Calculator
Base64 takes any sequence of bytes and rewrites it using only letters, digits and two punctuation marks. The point is not secrecy but safety: the output survives channels that would otherwise mangle raw binary.
Base64
QmFzZTY0IHR1cm5zIGFueSBieXRlcyBpbnRvIGEgc2FmZSBhbHBoYWJldCBvZiA2NCBjaGFyYWN0ZXJzLg==
- Input characters
- 61
- Output characters
- 84
- UTF-8 bytes
- 61
Base64 is an encoding, not encryption. It hides nothing and adds about a third to the size of the data.
The formula this calculator uses
3 bytes -> 4 Base64 characters (with = padding to a multiple of 4)
- bytes
- The input measured in bytes, not characters
- chars
- The Base64 output length, about 4/3 of the input
- =
- Padding that brings the output to a multiple of four
How to check the result by hand
- 1
Convert the text to UTF-8 bytes
Base64 works on bytes, so the text is written out as UTF-8 first. A plain ASCII letter is one byte, while an accented letter or an emoji is more.
- 2
Group the bytes in threes
Take the bytes three at a time. Each group of three bytes is twenty-four bits, which divides neatly into four six-bit chunks.
- 3
Map each six-bit value to a symbol
Each value from zero to sixty-three selects a character from the alphabet of A to Z, a to z, 0 to 9, plus and slash.
- 4
Pad the final group
If the last group held one byte, add two equals signs; if it held two, add one. This keeps the output a multiple of four characters long.
- 5
Use the URL-safe alphabet where needed
Swap plus for hyphen and slash for underscore, and drop the padding, when the result will sit inside a URL, a file name or a token.
For worked examples, common mistakes and the limits of this formula, read the full How To Encode Text To Base64 page.