What does Base64 encode do?
Base64 encoding writes any bytes, text or a whole file, using only 64 safe characters: A–Z, a–z, 0–9, + and /, plus = for padding. You need it whenever binary data has to travel through something that only carries text: an HTTP header, a JSON field, an environment variable, a data URL in CSS or an email attachment. The result is always about 33% larger than the input, because every 3 bytes become 4 characters.
This page opens the Base64 encoder and decoder already in Encode mode. Text is turned into bytes with the character set you pick (UTF-8 by default, so accents and emoji survive), and you choose the dialect: standard, or URL-safe with - and _ for URLs, file names and JWTs, with or without = padding. You can also encode raw bytes typed as hexadecimal, or drop a file of any type. It all runs in your browser and nothing is uploaded. To read Base64 back, open Base64 decode.
How to encode to Base64
- Type or paste your text in Text to encode, or drop a file onto the upload area to encode its bytes.
- Pick the dialect: tick URL-safe (- and _) for URLs and tokens, and untick Padding (=) if the receiver does not want trailing
=. - Leave Character set on UTF-8 unless the other side expects Latin-1 or UTF-16.
- To encode bytes instead of text, set Input is to Hex and paste them, for example
48 65 6c 6c 6f. - The Base64 appears in Result as you type. Click Copy, or Download to save it as a
.base64.txtfile.
Examples
Text with an accent (UTF-8)
Olá, mundo!T2zDoSwgbXVuZG8hURL-safe without padding
The text café? is Y2Fmw6k/ in standard Base64. With URL-safe on and Padding off it becomes:
Y2Fmw6k_No / or + left, so it can go in a URL path or query string without further escaping.
HTTP Basic authentication
Encoding user:pa55word gives the value of the header:
Authorization: Basic dXNlcjpwYTU1d29yZA==The Basic auth generator builds the full header for you.
Bytes typed as hex
With Input is set to Hex, 48 65 6c 6c 6f (or 0x48 0x65 0x6c 0x6c 0x6f) encodes to SGVsbG8=.
Common errors
- Character 11 cannot be written in Latin-1: you chose Latin-1 and the text has a character above U+00FF, such as the
€inPreço: 10 €. Choose UTF-8 or UTF-16. - The hex has an odd number of digits: each byte needs two hex digits. Check the last one.
- Different result from the command line:
echoadds a line break, soecho 'Olá, mundo!' | base64givesT2zDoSwgbXVuZG8hCg==. Useprintf '%s'instead. - btoa gives another value: in JavaScript,
btoa('Olá')encodes Latin-1 (T2zh), not UTF-8 (T2zDoQ==). See the code below.
FAQ
Does Base64 protect my data?
No. It is an encoding, not encryption: anyone can decode it. Use it to transport data, never to hide it. To hide a value, encrypt it; to check it was not changed, hash it with SHA-256.
How do I turn an image into a data URL?
Drop the image here to get its Base64, or use image to Base64, which writes the full data:image/...;base64, string ready for HTML and CSS.
When should I use Base64URL?
Whenever the value goes into a URL, a file name or a JWT. The standard + and / have special meanings there; - and _ do not.
How to encode Base64 in code
JavaScript
Encode the UTF-8 bytes, not the string, so non-ASCII text comes out right.
const bytes = new TextEncoder().encode('Olá, mundo!');
btoa(String.fromCharCode(...bytes)); // 'T2zDoSwgbXVuZG8h'
Buffer.from('café?').toString('base64url'); // Node.js: 'Y2Fmw6k_'Python
import base64
base64.b64encode("Olá, mundo!".encode("utf-8")).decode("ascii") # 'T2zDoSwgbXVuZG8h'
base64.urlsafe_b64encode("café?".encode()).decode().rstrip("=") # 'Y2Fmw6k_'Go
base64.StdEncoding.EncodeToString([]byte("Olá, mundo!")) // T2zDoSwgbXVuZG8h
base64.RawURLEncoding.EncodeToString([]byte("café?")) // Y2Fmw6k_Bash
printf '%s' 'Olá, mundo!' | base64
printf '%s' 'café?' | base64 | tr '+/' '-_' | tr -d '='