About base64 encoder / decoder
Base64 turns bytes into text made of 64 safe characters. It is used to carry binary data, such as images or files, inside text formats like JSON, email and HTML.
Not encryption
Anyone can decode Base64. It hides nothing, so never use it to protect passwords or secrets.
Details
- Output is about one third larger than the input.
- Padding with = characters brings the length to a multiple of 4.
- URL-safe Base64 uses - and _ instead of + and /.
A worked example
The text Hello encodes to SGVsbG8=. The trailing = is padding, because 5 bytes do not fill the last group of three. Text such as नमस्ते is first turned into UTF-8 bytes and then encoded, which is why plain btoa() in a browser fails on it.
Where you meet it
- Data URLs for small images, such as data:image/png;base64,...
- Email attachments and HTTP Basic authentication.
- JWTs, which use the URL-safe variant without padding.
