Base64 Encode and Decode
Paste text to get its Base64 encoding, or switch to Decode to turn a Base64 string back into readable text. Accents and emoji are encoded as UTF-8, and nothing leaves your browser.
0 words 0 characters 0 lines
Continue with this text: URL encoderText to hexText to binary
Your text stays in your browser: nothing is uploaded or stored on a server.
How to use the Base64 encoder and decoder
- Paste your text or Base64 string into Your text, or click Example to load a sample.
- Under Direction, choose Encode text → Base64 or Decode Base64 → text. The result updates as you type.
- Tick URL-safe (- and _ , no padding) if the encoded string will go into a URL, a file name or a JSON Web Token.
- Tick Each line separately when every line is its own value, such as a list of IDs or tokens.
- Click Copy, or Use as input to run the result through another tool, for example the URL encoder.
If the input cannot be decoded, the result box stays empty and a message appears above it.
What each option changes
| Option | Encode | Decode |
|---|---|---|
| Neither ticked | The whole text, line breaks included, becomes one Base64 string | Spaces and line breaks are removed, then the rest is decoded as one string |
| URL-safe | + becomes -, / becomes _, and the = padding is removed |
No effect: - and _ are always accepted |
| Each line separately | Each line gets its own Base64 string, one per line | Each line is decoded on its own |
Two details about Each line separately: empty lines are skipped, so the output has no blank lines, and the line breaks themselves are not encoded. Without the option, a line break inside your text is part of the data: Alice and Bob on two lines encode to QWxpY2UKQm9i, where the group Y2UK holds ce plus the line break.
How encoding works, with examples
The tool first turns your text into bytes with UTF-8, the encoding used by almost every web page and API. Base64 then takes the bytes three at a time (24 bits) and writes each group as four characters from a 64-character alphabet: A–Z, a–z, 0–9, + and /. If one or two bytes are left over at the end, the output is padded with == or =, as RFC 4648 specifies. That is why encoded text is always about a third longer than the original.
| Text | UTF-8 bytes | Base64 | URL-safe |
|---|---|---|---|
Man |
3 | TWFu |
TWFu |
Hello |
5 | SGVsbG8= |
SGVsbG8 |
foobar |
6 | Zm9vYmFy |
Zm9vYmFy |
café |
5 | Y2Fmw6k= |
Y2Fmw6k |
👋 |
4 | 8J+Riw== |
8J-Riw |
~~~??? |
6 | fn5+Pz8/ |
fn5-Pz8_ |
admin:s3cret |
12 | YWRtaW46czNjcmV0 |
YWRtaW46czNjcmV0 |
Accented letters take two bytes in UTF-8 and most emoji take four, so café is 5 bytes, not 4. The Example text, Hello, world! Héllo 👋, is 21 characters but 25 bytes, and encodes to SGVsbG8sIHdvcmxkISBIw6lsbG8g8J+Riw==. Encoding the same text in a tool that uses another character set (such as Latin-1 or UTF-16) gives a different string, so check which one the other side expects if a result does not match.
The tool writes the Base64 as one unbroken line. Some programs wrap it every 76 characters instead, as email (MIME) does; GNU base64 wraps at 76 by default. Both decode to the same data.
Decoding rules and error messages
The decoder is lenient about format but strict about content:
- Spaces, tabs and line breaks are ignored, so Base64 copied from an email or wrapped at 76 characters decodes as one string.
- Both alphabets are accepted.
PDw/Pz8+Pg==andPDw_Pz8-Pgboth decode to<<???>>. - Missing padding is added.
SGVsbG8decodes toHello, just likeSGVsbG8=. - A data URL prefix is removed. Paste a whole
data:image/png;base64,iVBORw0KGgo=and the part up to and including the comma is dropped before decoding. - Any other character stops decoding with the message “This is not Base64: it contains characters outside A–Z, a–z, 0–9, +, / and =.”
- An incomplete string or an
=in the middle stops decoding with the message “This Base64 is incomplete or has = in the wrong place: = may only appear at the end, and a value has 4n, 4n+2 or 4n+3 characters without it.” A single leftover character (abcde) cannot be decoded, and neither can two values joined together, such as two lines that each end in=. When the input has several lines, the message adds “If every line is its own value, tick “Each line separately”.” The lines are not split for you. - Bytes that are not UTF-8 text show as �, with a warning. Decoding
iVBORw0KGgo=, the first bytes of a PNG image, gives�PNGfollowed by control characters, and the status line says “The decoded bytes are not valid UTF-8 text (8 bytes): this is probably a file or binary data.” The data is fine, but it is an image, not text, and copying the result does not give you the original bytes back.
| Base64 | Decoded |
|---|---|
SGVsbG8K |
Hello followed by a line break |
eyJ1c2VyIjoiYW5hIiwiYWRtaW4iOmZhbHNlfQ |
{"user":"ana","admin":false} |
w6k |
é |
SGVsbG8! |
Error: not Base64 |
When people need Base64
- Reading a JSON Web Token. A JWT is a series of URL-safe Base64 parts joined by dots, usually three. Paste the middle part (the payload) on its own and decode it to see the claims, like the
{"user":"ana",...}example above. Decoding does not check the signature. - HTTP Basic authentication. The
Authorization: Basicheader carriesuser:passwordin Base64. RFC 7617’s example headerQWxhZGRpbjpvcGVuIHNlc2FtZQ==decodes toAladdin:open sesame, which is why Basic auth should only be used over HTTPS. - Config files and environment variables. When a setting must be given in Base64, encode with the URL-safe option off and check that no line break slipped in at the end of your input:
secretandsecretplus a line break give different strings. - Data URLs. A
data:text/plain;base64,...URL embeds the content in the link itself; the part after the comma is ordinary Base64, and you can paste the whole URL because the decoder removes the prefix. - Email source. Message parts marked
Content-Transfer-Encoding: base64can be decoded here when they contain text.
Base64 is not a way to hide anything. For text that only needs to be safe inside a link, URL encoding is shorter and stays readable; to look at the raw bytes instead, use text to hex. The guide What is Base64 encoding explains the alphabet and its uses in more depth.
Base64 on the command line, in Python and in PowerShell
These commands give the same results as the tool for the same UTF-8 text.
Linux (GNU coreutils). Use printf, which adds no line break; -d decodes and -w 0 turns off the 76-character wrapping, which is handy for an image or any other file:
printf 'café' | base64
echo 'Y2Fmw6k=' | base64 -d
base64 -w 0 picture.png
The first two lines print Y2Fmw6k= and café.
Python 3. b64encode takes bytes, so encode the string to UTF-8 first:
import base64
base64.b64encode('café'.encode('utf-8')) # b'Y2Fmw6k='
base64.b64decode('Y2Fmw6k=').decode('utf-8') # 'café'
base64.urlsafe_b64encode(b'~~~???') # b'fn5-Pz8_'
PowerShell (.NET). Convert the string to UTF-8 bytes, then to Base64, and the reverse:
[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes('café'))
[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String('Y2Fmw6k='))
Python’s urlsafe_b64encode keeps the = padding, while this tool’s URL-safe option removes it. Python’s b64decode raises an error on missing padding, so add = until the length is a multiple of 4 when decoding unpadded strings there.
Questions
Is Base64 encryption?
No. Base64 only changes how bytes are written down; anyone can decode it without a key. A password or API key in Base64 (for example in an HTTP Basic auth header) is as readable as plain text to anyone who sees it.
Why does my Base64 end with = or ==?
Base64 turns every 3 bytes into 4 characters. When the text length in bytes is not a multiple of 3, the last group is filled with one or two = signs. The URL-safe option leaves them out, and the decoder accepts Base64 with or without them.
Why do I get a different result from echo in the terminal?
echo adds a line break to the end, so echo Hello | base64 encodes 6 bytes and prints SGVsbG8K, not SGVsbG8=. Use printf 'Hello' | base64 for the same result as this tool.
Can I encode an image or a file to Base64 here?
Not yet. This tool encodes text, and the Open file button reads plain-text files only. For an image, run base64 -w 0 picture.png on Linux, or use the Python or PowerShell lines on this page.
Why does the decoded text show � characters?
The decoded bytes are not valid UTF-8 text, and the tool says so above the result with the number of bytes. That usually means the Base64 holds an image, a compressed file or encrypted data rather than text, so there is no readable version to show, and the copied result is not the original file.
Is my text uploaded?
No. Encoding and decoding run in your browser with its built-in TextEncoder, btoa and atob functions. Nothing you paste is sent to a server.
What is the difference between Base64 and URL encoding?
Base64 rewrites all of the data with 64 safe characters and makes it about a third longer. URL encoding keeps letters and digits as they are and replaces only unsafe characters with % codes, so the result stays readable.