Base64 Encode and Decode
Encode text or any file and decode it back, in UTF-8, Latin-1, ASCII or UTF-16. URL-safe, with or without padding, MIME and PEM line breaks, data: URIs. Decoded files are recognised, previewed and ready to download. Nothing leaves your browser.
- Free, no sign-up
- Text or any file
- 4 text encodings
- URL-safe, no padding
- File preview and download
- Nothing uploaded
People also use
How to encode or decode in three steps
Type or paste text in the left box and the Base64 appears on the right as you type. Switch Mode to Decode, paste an encoded string, and you get the original text back or, if it holds a file, a preview and a download button. Press Encode a file to turn any file into text instead.
Every common variant is covered: four text encodings, the URL-safe alphabet, padding on or off, line breaks for email and PEM files, data: URIs and one result per line. When decoding you do not have to clean anything first. URL-safe characters, missing padding, spaces, line breaks and a data: prefix are all accepted.
All of it runs in your browser. The text and files you work with are never uploaded, so the page is fine for tokens, config values and private documents.
- 1
Pick Encode or Decode
Choose the Mode. Encode turns text or a file into encoded text; Decode turns it back into text or a file. Change Text encoding if your text is not UTF-8.
- 2
Type, paste or drop
Type or paste in the left box, or drop a file on it. With Live ticked the result updates as you type; untick Live to get an Encode or Decode button instead.
- 3
Copy, swap or download
Press Copy to take the result, Swap to use it as the new input, or Download. A decoded file shows its type, a preview when the browser can show one, and a download button.
Your settings, such as Mode, Text encoding, URL-safe, Padding, Line breaks and Live, are remembered in this browser for next time. The text and files themselves are never saved.
How it works: 3 bytes become 4 characters
Base64 is a way to write any bytes with only 64 safe characters: A to Z, a to z, 0 to 9, plus + and /. It exists because many older systems, email above all, were built for plain text and could damage raw binary data on the way. Written in those 64 characters, a picture or a PDF can travel anywhere text can.
The rule is simple. The input is cut into groups of 3 bytes, which is 24 bits. Those 24 bits are split into four pieces of 6 bits, and each piece, a number from 0 to 63, picks one character from the alphabet. So every 3 bytes become 4 characters.
When the input length is not a multiple of 3, the last group is short. One leftover byte becomes 2 characters plus ==, and two leftover bytes become 3 characters plus =. Those equals signs are the padding, and they only ever appear at the end.
Because 3 bytes turn into 4 characters, the encoded result is about 33% bigger than the original, a little more if you add line breaks. The tool shows both sizes above the boxes, and in Encode mode the increase too, for example +33%.
| Input | Bytes | Encoded | Why |
|---|---|---|---|
| M | 1 | TQ== | 1 byte gives 2 characters and 2 padding signs |
| Ma | 2 | TWE= | 2 bytes give 3 characters and 1 padding sign |
| Man | 3 | TWFu | 3 bytes give 4 characters, no padding |
| Hello | 5 | SGVsbG8= | 3 + 2 bytes give 4 + 4 characters |
| Hello, world! | 13 | SGVsbG8sIHdvcmxkIQ== | 13 bytes give 20 characters |
Encoding, not encryption
This is an encoding, not encryption. There is no key and no secret: anyone who sees the text can decode it in a second, with this page or with one command. It hides nothing.
That matters because encoded values often look secret. HTTP Basic authentication headers, Kubernetes secrets and many config files store passwords this way, and the JWT Decoder shows that a JSON Web Token is mostly encoded JSON that anyone can read. Treat an encoded password exactly like the plain password.
If you need to keep something private, encrypt it, for example with Protect PDF for a document, and use a long random secret from the Password Generator. Encoding is also not compression: the output is always larger than the input, so compress first and encode afterwards if size matters.
Base64 encode online: UTF-8, Latin-1, ASCII or UTF-16
To base64 encode online, keep Mode on Encode and type. The question that matters most is which bytes your text turns into, because the encoding works on bytes, not on letters. The Text encoding menu decides that.
UTF-8 is the default and almost always the right choice. It is what the web, JSON, Linux and most APIs use. English letters take one byte each; accented letters, other scripts and emoji take two to four bytes, so é becomes two bytes and 😀 becomes four.
ISO-8859-1 (Latin-1) gives one byte per character for Western European text and matches what older systems, and the browser's own btoa function, expect. Characters outside it are written as a question mark. ASCII allows only characters 0 to 127; type anything else and the tool tells you to choose UTF-8 rather than guessing. UTF-16 LE uses two bytes per character, little-endian, which is what Windows PowerShell expects for its -EncodedCommand option.
The same word can therefore give different results. café is Y2Fmw6k= in UTF-8 but Y2Fm6Q== in Latin-1. If your result does not match another system, try the other encodings before anything else.
When you decode, the same menu tells the tool how to read the bytes back into text. If the result shows odd pairs such as é where é should be, the bytes were UTF-8 read as Latin-1, or the other way round.
Base64 decode online: paste it as it is
To base64 decode online, switch Mode to Decode and paste. You do not have to tidy the input. Spaces, tabs and line breaks are ignored, the URL-safe characters - and _ are understood, missing = padding is added back, and a data: prefix such as data:image/png;base64, is removed and its type remembered.
A small note under the result tells you what was fixed, for example URL-safe alphabet, missing padding added, or data URI (image/png). Characters that cannot be part of the encoding at all, such as quotes or commas copied by accident, are skipped and counted in the note, so you know the input was not clean.
The one thing that cannot be repaired is a wrong length. Without its padding, valid input always has a number of characters that leaves a remainder of 0, 2 or 3 when divided by 4. A remainder of 1 means a character is missing or extra, and the tool says so instead of returning broken bytes.
If the decoded bytes are readable text, you see the text and can copy it or swap it back. If they are a file, a green box names the type and offers a download, as described below. In Decode mode the file button reads Open a .txt file: choose a .txt or .b64 file holding encoded text and its contents are loaded into the box.
Pasted an encoded string into Encode mode by mistake? When the text looks encoded, a hint appears under the box with a Decode it instead link.
Base64 url safe: - and _ instead of + and /
The standard alphabet uses + and /, and both mean something in a web address: + can turn into a space, and / separates folders. The URL-safe variant, defined in RFC 4648, swaps them for - and _. It is what JSON Web Tokens, many API keys, signed links and file names use.
Tick URL-safe (- and _) in Encode mode to get it. This base64 url safe form, often written base64url, usually goes together with no padding, because = also needs escaping in a URL. Untick Padding (=) as well when a format asks for both.
In Decode mode there is nothing to tick: both alphabets are read automatically, and the note says URL-safe alphabet when - or _ was found. If you want to keep the standard alphabet and put the value in a query string anyway, percent-encode the result with URL Encode.
Base64 encode without padding: dropping the = signs
The = signs at the end only say how many bytes the last group had. A decoder can work that out from the length, so many formats leave them out. JWTs, URL-safe tokens and some APIs expect no padding; email, PEM files and most libraries write it.
To base64 encode without padding, untick Padding (=). A one-byte remainder then ends in 2 characters instead of 2 plus ==, and a two-byte remainder in 3 characters instead of 3 plus =. Nothing else in the output changes.
Decoding works either way. If padding is missing, the tool adds it back and says missing padding added, so you can paste a token straight from a URL.
Line breaks, data: URIs and one value per line
Line breaks splits long output into lines. Every 76 (MIME, email) follows the email standard used for attachments. Every 64 (PEM) matches certificate and key files that sit between -----BEGIN and -----END lines. None, the default, gives one long line, which is what JSON, HTML and most code want. Lines end with CRLF, as both standards specify.
As data: URI adds a prefix so the result can be used directly as a link or an image source. For a file it uses the file's own type, such as image/png or application/pdf; for text it uses text/plain with the charset you chose. For files, line breaks are left out in this mode, because a data URI should be one piece.
Each line separately treats every line of the input as its own value. Paste a list of ten strings and you get ten encoded lines back, in the same order, instead of one block. It works in Decode mode too, which is handy for a column copied from a spreadsheet or a log. It is not available for files.
Base64 encode file: any file into text
Press Encode a file, or drop a file on the left box, to turn it into text. Any type works: PDF, ZIP, fonts, audio, Word documents, certificates. The file is read by your browser, so a large one takes a moment, but it never leaves your device.
When you base64 encode file contents, the same options apply: URL-safe, Padding, Line breaks and As data: URI. Each line separately is switched off, because a file is one value. The size line shows the original size, the encoded size and the increase, about +33%.
Long results are awkward to copy, so Download as .txt saves the output as a text file named after the original, for example report.pdf.b64.txt. Press Remove file, type text instead to go back to typing.
One practical note: very large outputs are heavy for a browser text box and for whatever you paste them into. Putting a 20 MB video into a web page or a JSON body as text is rarely a good idea; link to the file instead.
Base64 encode image for HTML, CSS and JSON
A common reason to base64 encode image files is to put a small icon or logo straight into HTML, CSS, an email template or a JSON payload, with no separate file to load. Drop the image, tick As data: URI, and copy the result into an img src attribute or a CSS url().
This page treats an image like any other file. For image-only work, Image to Base64 is made for the job, with ready-made HTML and CSS snippets. Shrinking the picture first matters, since the text is a third bigger than the file; Compress Image and Resize Image help with that.
Inline images work best when they are small, a few kilobytes at most. Bigger ones make every page load heavier, cannot be cached on their own and delay the first paint. SVG icons are often better pasted as plain SVG markup.
Base64 decode file: type recognised from the first bytes
Encoded text does not say what it contains, but most file formats begin with a fixed signature, sometimes called magic bytes. After decoding, the tool checks those first bytes. If it finds a known one, a green box shows the type and size, a preview when the browser can show or play it, and a Download button that saves the file with the right extension, such as decoded.pdf.
So to base64 decode file data from an API response, an email source or a database field, paste it in Decode mode and press Download. If no signature matches and the bytes are not valid text, the box says Binary data and saves decoded.bin.
| Kind | Recognised as | Preview |
|---|---|---|
| Images | PNG, JPG, GIF, WebP, AVIF, BMP, ICO, SVG, HEIC | Shown when the browser supports the format |
| Documents | PDF, Word (.docx), Excel (.xlsx), PowerPoint (.pptx) | PDF in a viewer; Office files download |
| Archives | ZIP, GZIP | Download |
| Audio | MP3, OGG, WAV | Player with controls |
| Video | MP4, WebM | Player with controls |
| Fonts | WOFF2, TTF and OTF (saved as .ttf) | Download |
Word, Excel and PowerPoint files are ZIP archives inside, so the tool looks a little deeper to tell them apart. Previews are made for files under 60 MB; bigger ones can still be downloaded. Once saved, Office files open in their usual apps, or you can turn them into PDFs with Word to PDF and Excel to PDF.
Base64 decode to PDF: preview, then download
PDFs are often sent as encoded text: e-signature and invoicing APIs, shipping label services and raw email sources all do it. To base64 decode to pdf, paste the string, with or without its data:application/pdf prefix, in Decode mode. Encoded PDFs start with JVBERi0, which is %PDF- encoded.
The PDF opens right in the page so you can check it is the right document, and Download .pdf saves it. If the viewer stays blank, the data may be cut short or damaged: check that the whole string was copied, and try Repair PDF on the saved file.
Need the text or the pages out of it afterwards? PDF to Text, PDF to JPG and Compress PDF work on the saved file.
Base64 decode to image: see it, then save it
Encoded images turn up in HTML source, CSS, JSON from APIs and chat exports. To base64 decode to image, paste the string in Decode mode; a data:image prefix is fine. PNG, JPG, GIF, WebP, AVIF, BMP, ICO and SVG are recognised and shown, and Download saves the file with its extension. HEIC is recognised too, but most browsers other than Safari cannot show it, so download it and use HEIC to JPG.
A few telltale starts help when you are not sure what you have: iVBORw0KGgo is a PNG, /9j/ is a JPG, R0lGOD is a GIF, and UklGR is a RIFF file such as WebP or WAV.
For pictures only, Base64 to Image is the dedicated tool, and Convert Image changes the saved file to another format.
Base64 decode to hex: look at the raw bytes
Sometimes the decoded value is not text or a file but raw bytes: a hash, a key, an ID, a signature or a binary protocol message. To base64 decode to hex, decode as usual and switch View from Text to Hex.
The hex view shows 16 bytes per row: the offset on the left, the bytes as hex pairs in the middle and the printable characters on the right, with dots for the rest. It shows the first 4 KB, enough to inspect a file header or a short value.
This is also how you compare two forms of the same hash. A SHA-256 written as 44 characters ending in one = is 32 bytes, and the hex pairs in the view are the 64-character hex form you see on download pages, with spaces between them. The Hash Generator can give you either form directly.
Command line: macOS, Linux, certutil and PowerShell
The same conversion is built into every operating system. Results match this page as long as the input bytes match.
| System | Encode | Decode |
|---|---|---|
| macOS | base64 -i in.pdf -o out.txt | base64 -D -i out.txt -o in.pdf |
| Linux | base64 -w 0 in.pdf > out.txt | base64 -d out.txt > in.pdf |
| Windows Command Prompt | certutil -encode in.pdf out.txt | certutil -decode out.txt in.pdf |
| PowerShell | [Convert]::ToBase64String([IO.File]::ReadAllBytes("in.pdf")) | [IO.File]::WriteAllBytes("in.pdf", [Convert]::FromBase64String($s)) |
Three habits cause most mismatches. echo adds a newline at the end, so use echo -n or printf when you pipe text in. The Linux tool wraps its output at 76 characters unless you add -w 0. certutil writes -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- lines around its output, which you remove before using the text elsewhere.
For text in PowerShell, turn the string into bytes first with [Text.Encoding]::UTF8.GetBytes("text"). For -EncodedCommand, use [Text.Encoding]::Unicode instead, which matches the UTF-16 LE option here.
In code: JavaScript, Node.js and Python
| Where | Encode | Decode |
|---|---|---|
| JavaScript, text | btoa(String.fromCharCode(...new TextEncoder().encode(s))) | new TextDecoder().decode(Uint8Array.from(atob(b), (c) => c.charCodeAt(0))) |
| Node.js | Buffer.from(s).toString("base64") | Buffer.from(b, "base64").toString() |
| Python | base64.b64encode(s.encode()).decode() | base64.b64decode(b).decode() |
| Python, URL-safe | base64.urlsafe_b64encode(data) | base64.urlsafe_b64decode(data) |
In JavaScript, btoa() encodes and atob() decodes, but they only accept characters 0 to 255, like the Latin-1 option here, so btoa("€") throws an error. For real text, turn it into UTF-8 bytes with TextEncoder first, as in the table, and read the bytes back with TextDecoder. The spread in the first line is fine for short strings; for large data, convert in chunks.
Python's standard module has b64encode and b64decode for the standard alphabet and urlsafe_b64encode and urlsafe_b64decode for the URL-safe one. They work on bytes, so encode text first, and they keep the padding; strip the = signs yourself if a format wants none. In Node.js, Buffer does both directions, and the base64url option gives the URL-safe form without padding.
Where you meet encoded data
Email attachments
MIME email stores every attachment as text in lines of 76 characters. Copy an attachment's block from a message's raw source and decode it to get the file back.
Data URIs in HTML and CSS
Small icons, fonts and placeholders are embedded inline, so the page needs one request fewer.
APIs and JSON
JSON cannot hold raw bytes, so APIs send files, images, PDFs and signatures as encoded strings. The JSON Formatter makes a decoded payload readable.
Tokens and keys
JWTs, many API keys and some cookies use the URL-safe alphabet. Decoding shows what is inside; it does not let you change a signed token.
Certificates and keys
PEM files are DER bytes written in lines of 64 characters between BEGIN and END lines.
Basic authentication
The Authorization: Basic header is just user:password encoded, which is why it must only travel over HTTPS.
Config and secrets
Kubernetes secrets and many deployment tools store values encoded, not encrypted.
Debugging
Decode a mystery string from a log, a cookie or a URL to see whether it is text, JSON or a file.
Troubleshooting
The number of characters is wrong
One character is too many or missing, usually from a copy that was cut short. Copy the whole value again, including the very end.
Odd characters such as é in the result
The text encoding does not match. Switch Text encoding between UTF-8 and ISO-8859-1 (Latin-1) until the text reads correctly.
The result box says Binary file: see below
The decoded bytes are not valid text in the chosen encoding, so they are treated as a file. Use the download in the green box, or switch View to Hex to look at the bytes.
The note says invalid characters skipped
Something other than encoded characters was in the input, such as quotes, commas or a JSON key. Paste only the value itself.
It says characters outside ASCII
You chose ASCII and typed a letter such as é or €. Choose UTF-8, which handles every character.
My result differs from another tool
Check the text encoding, the line endings (Windows uses CRLF, others LF), a trailing newline, and whether the other tool uses URL-safe characters, padding or line breaks.
Copy and Swap are greyed out
The result is a binary file, not text. Use the Download button in the green box instead.
The preview is blank
The data may be incomplete or damaged, or the browser cannot show that format, such as HEIC outside Safari. Download the file and open it in another app.
Nothing happens when I type
Live is unticked. Press the red Encode or Decode button, or tick Live again.
All settings at a glance
| Setting | Choices | What it does |
|---|---|---|
| Mode | Encode, Decode | Text or file to encoded text, or back again |
| Text encoding | UTF-8, ISO-8859-1 (Latin-1), ASCII, UTF-16 LE | How text becomes bytes, and bytes become text |
| Live | On, off | Update as you type, or wait for the Encode or Decode button |
| URL-safe (- and _) | On, off | Use - and _ instead of + and / (Encode) |
| Padding (=) | On, off | Add = signs to complete the last group (Encode) |
| Line breaks | None, Every 76 (MIME, email), Every 64 (PEM) | Wrap long output into lines (Encode) |
| As data: URI | On, off | Add a data: prefix with the file or text type (Encode) |
| Each line separately | On, off | One result per input line; text only |
| View | Text, Hex | Show decoded bytes as text or as a hex dump (Decode) |
| Encode a file / Open a .txt file | Any file | Encode a file, or load encoded text from a file |
Is it safe? Done in your browser, nothing uploaded
Encoding and decoding happen in this page, in your browser, with the page's own code. Text, tokens and files are not uploaded, not logged and not put in the address bar. Previews of decoded files are temporary local links that only your browser can open.
The page remembers only your settings, such as Mode, Text encoding and the encode options, in this browser's local storage. Your text and files are never saved. You can clear the stored settings in your browser's site data.
Remember the other half of safety: the encoded text itself protects nothing. Anyone you share it with, or anyone who sees it in a log, can read it.
What to do next
Working with web data? URL Encode makes values safe for query strings, the JWT Decoder reads tokens, the JSON Formatter tidies decoded JSON, and the Hash Generator makes SHA-256 or MD5 checksums in hex or in this encoding.
Got a file out of the decoder? Compress PDF, PDF to Word or Convert Image are good next steps, depending on what you saved.
Frequently asked questions
How do I base64 decode online?
Switch Mode to Decode and paste the encoded text in the left box. With Live ticked the result appears at once. Spaces, line breaks, URL-safe characters, missing padding and a data: prefix are all accepted.
How do I base64 encode online?
Keep Mode on Encode and type or paste in the left box; the result appears on the right as you type. Choose the Text encoding first if your text must be Latin-1, ASCII or UTF-16 LE rather than UTF-8. Press Copy to take it.
How can I base64 decode to pdf?
Paste the encoded PDF in Decode mode. The tool recognises it from its first bytes, shows it in a viewer and offers Download .pdf. Encoded PDFs usually start with JVBERi0.
Can I base64 decode to image and save the picture?
Yes. Paste the string, with or without a data:image prefix, in Decode mode. PNG, JPG, GIF, WebP, AVIF, BMP, ICO and SVG are recognised and previewed, and the download gets the right extension.
How do I base64 encode image files for HTML or CSS?
Press Encode a file, pick the image and tick As data: URI. Copy the result into an img src attribute or a CSS url(). Keep inline images small, because the text is about a third bigger than the file.
How do I base64 decode file data from an API?
Paste the value in Decode mode. If the first bytes match a known format, a green box shows the type and a Download button saves it with the right extension. Unknown binary data is saved as decoded.bin.
Can I base64 encode file types other than images?
Yes, any file: PDF, ZIP, Word, audio, fonts or certificates. Press Encode a file or drop it on the left box, then copy the result or use Download as .txt. Nothing is uploaded.
How do I base64 decode to hex?
Decode as usual, then switch View from Text to Hex. You see the offset, the hex bytes and the printable characters, 16 bytes per row, for the first 4 KB.
How do I base64 encode without padding?
Untick Padding (=) in Encode mode. The = signs at the end disappear and nothing else changes. Decoding here works with or without padding.
What is base64 url safe encoding?
It replaces + with - and / with _, so the result can go in a URL or a file name without escaping. It is defined in RFC 4648 and used by JWTs. Tick URL-safe (- and _) to encode it; decoding reads both alphabets automatically.
What is Base64?
It is a way to write any data with 64 plain characters: letters, digits, + and /. Every 3 bytes become 4 characters, so binary files can travel through email, JSON, HTML and other text-only places.
Is Base64 encryption?
No. It is an encoding with no key or secret, and anyone can decode it in seconds. Never treat an encoded password or token as protected; encrypt sensitive data instead.
Why is the output about 33% bigger?
Each character carries 6 bits but takes a whole byte to store. So 3 bytes of input become 4 characters, a third more, plus a little for padding and line breaks. The size line above the result shows the exact increase.
What are the = signs at the end?
They are padding. They show that the last group had only one or two bytes instead of three: two = signs mean one byte, one = sign means two bytes.
Which text encoding should I choose?
UTF-8, unless a system tells you otherwise. Choose ISO-8859-1 (Latin-1) to match older systems or the browser's btoa, ASCII to make sure only basic characters are used, and UTF-16 LE for PowerShell's -EncodedCommand.
What do the line break options do?
Every 76 (MIME, email) splits the output into 76-character lines as email requires. Every 64 (PEM) matches certificate and key files. None gives a single line, which suits JSON, HTML and code.
What does Each line separately do?
It encodes or decodes every line of the input on its own, so a list of values gives a list of results in the same order. It works for text, not for files.
Why does my result differ from the command line?
Usually the input differs. echo adds a newline unless you use echo -n, the Linux tool wraps at 76 characters unless you add -w 0, and Windows files may end lines with CRLF. Also check the text encoding.
How do I encode and decode on Windows without a browser?
In Command Prompt, run certutil -encode or certutil -decode with an input file and an output file. In PowerShell, use [Convert]::ToBase64String and [Convert]::FromBase64String.
Why does it say the number of characters is wrong?
Valid encoded text never leaves a remainder of 1 when its length without padding is divided by 4. A remainder of 1 means a character is missing or extra, usually because the copy was cut short. Copy the whole value again.
Is my data uploaded?
No. Everything is encoded and decoded in your browser, and previews of decoded files are made locally. Only your settings are remembered in this browser; text and files are never saved.
Encode or decode now
Text or files, standard or URL-safe, with a preview for decoded files. Free, private and done on your device.
Back to the toolLast updated October 2026 · Written and maintained by the FlipMyFormat team