Base64 Encoder & Decoder
Encode and decode Base64 for text, files and images — with data URIs, in your browser.
Base64 Encoder and Decoder - Convert Text to Base64 Online
Base64 turns arbitrary bytes into a short, safe alphabet of 64 characters that survives email headers, JSON strings, URLs, XML attributes and copy-paste. This free online Base64 encoder and decoder converts in both directions instantly: paste text and click Encode, paste a Base64 string and click Decode, or switch to the File tab to turn an image, a PDF or any other file into Base64.
There is no account to create and no queue to wait in, and nothing is uploaded: a file you choose is read by the browser itself. The conversion happens with native JavaScript, so it is fast enough for long payloads and private enough for internal data.
What is Base64 encoding?
Base64 is a binary-to-text encoding scheme. It reads your data three bytes at a time, splits those 24 bits into four 6-bit groups, and maps each group to one character from the set A-Z a-z 0-9 + /. When the input length is not divisible by three, one or two = characters are appended as padding. The result is roughly 33% larger than the original, but it contains no control characters, no line breaks and nothing that a text-based protocol will mangle.
How to encode or decode Base64 online
- Use the Text tab for text, or the File tab to encode a file.
- Paste your text - plain text, JSON, an XML fragment or an existing Base64 string.
- Click Encode to convert readable text into Base64, or Decode to turn a Base64 string back into its original content.
- On the File tab, drop a file onto the upload area and the Base64 appears straight away; tick Data URI prefix if you want a ready-to-paste
data:value. - Use Copy to take the result, Download to save it as a file, or Clear to start over.
How to convert an image to Base64
Open the File tab and drop in the PNG, JPG, SVG or icon you want to embed. The tool reads the bytes locally and prints the Base64 immediately, with a preview so you can confirm you picked the right image. Tick Data URI prefix and you get the complete data:image/png;base64,... value that goes straight into a CSS background-image rule, an img tag or a JSON field. The other direction works too: paste a data URI into the Text tab, click Decode, and the image is previewed and offered as a download instead of being dumped out as unreadable characters. Files up to 10 MB are supported.
Decode Base64 to a PDF
APIs that return invoices, labels or reports often send the PDF as one long Base64 string, usually starting with JVBERi0 - the Base64 of %PDF-. Paste it into the Text tab, with or without a data:application/pdf;base64, prefix, and click Decode. The tool recognises the PDF from its first bytes, shows it in your browser's own PDF viewer right below the output, and offers Download to save it as decoded.pdf; Open the PDF in a new tab gives it a full window. Going the other way, drop a PDF onto the File tab to get its Base64. The Base64 to PDF page opens the decoder ready for exactly this.
Where Base64 is actually used
- HTTP Basic Authentication headers, which carry
username:passwordas a single Base64 string. - Data URIs that embed a small icon or font directly in CSS or HTML instead of a separate request.
- Email attachments - MIME has encoded binary parts in Base64 since the 1990s.
- JSON Web Tokens, where the header and payload are Base64URL segments.
- API payloads that must carry a file, a certificate or a signature inside a JSON string field.
- Kubernetes Secrets and many CI/CD systems, which store values Base64-encoded in YAML.
Base64 is encoding, not encryption
This is the single most common misunderstanding, and it matters. Base64 has no key and no secret - anyone who sees the string can decode it in one click, exactly as you are about to do on this page. Never treat a Base64 string as a way to hide a password, an API key or personal data. If you need secrecy, encrypt the data first and Base64-encode the ciphertext for transport. If you need to prove data has not changed, use a checksum from the hash generator instead.
Standard Base64 vs Base64URL
Two characters make the difference. Standard Base64 uses + and /, which both have special meaning inside a URL or a filename. Base64URL replaces them with - and _ and usually drops the = padding. JWTs, OAuth parameters and many modern APIs use the URL-safe variant, so if a token refuses to decode, check for those substitutions before assuming the data is corrupt.
Common Base64 problems and how to fix them
- Invalid character errors: a copied string picked up a stray quotation mark or some surrounding text. Spaces and line breaks are stripped for you, so remove only what is not part of the string itself.
- Wrong padding: a valid Base64 string has a length divisible by four. Missing
=characters are restored automatically, and Base64URL with-and_is converted as well. - Data URI prefix: you can leave
data:image/png;base64,in place - it is detected, stripped and used to name the decoded file. - Garbled accents or emoji: the original bytes were not UTF-8. Genuinely binary content is detected and offered as a download instead of being shown as broken characters.
- Unexpectedly large output: the 33% growth is normal; use it as a sanity check that the conversion ran.
Your data stays on your device
Encoding and decoding both run entirely client-side, and a file you choose is read by the browser rather than sent anywhere. Nothing is transmitted to a server, written to a log or retained after you close the tab, which makes this safe for the kind of data people usually paste into a converter - session tokens, config values and support tickets containing customer details.
Base64 encode and decode from the command line or in code
| Platform | Encode | Decode |
|---|---|---|
| Linux / macOS | base64 file.png or echo -n 'text' | base64 | base64 -d encoded.txt (-D on older macOS) |
| PowerShell | [Convert]::ToBase64String([IO.File]::ReadAllBytes('file.png')) | [Convert]::FromBase64String($s) |
| Python | base64.b64encode(data) | base64.b64decode(s) |
| JavaScript | btoa(str) in the browser, Buffer.from(str).toString('base64') in Node | atob(s) / Buffer.from(s, 'base64') |
| PHP | base64_encode($data) | base64_decode($s) |
| Java | Base64.getEncoder().encodeToString(bytes) | Base64.getDecoder().decode(s) |
One trap: btoa only accepts Latin-1, so encoding text with accents or emoji in the browser needs a TextEncoder step first. The tool above handles UTF-8 for you, which is why it is often quicker than remembering the incantation.
Related tools
Base64 rarely travels alone. Inspect tokens built from Base64URL segments with the JWT decoder, escape values for query strings with the URL encoder, tidy the decoded payload with the JSON formatter, and generate checksums with the hash generator.