Base64 Encoder & Decoder
Encode text or binary files to Base64, or decode Base64 strings back to their original format. Supports file uploads for images, PDFs, and other binary data.
What is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that represents binary data in an ASCII string format using a set of 64 characters (AβZ, aβz, 0β9, +, and /). It is widely used across the web for embedding images directly into HTML or CSS, transmitting binary data through text-based protocols like email (MIME) and JSON APIs, and storing complex data in text-only formats such as XML and YAML.
The name "Base64" comes from the fact that each character in the encoded string represents exactly 6 bits of the original data (26 = 64 possible values). Three bytes (24 bits) of binary data are split into four 6-bit groups, each mapped to a Base64 character. If the input isn't a multiple of 3 bytes, padding characters (=) are added to the end.
Why Use This Base64 Tool?
Our Base64 Encoder/Decoder runs entirely in your browser β your data never leaves your computer. It handles both text and binary files, making it ideal for developers who need to:
- Embed images in HTML/CSS: Convert PNG, JPEG, or SVG files to Base64 data URIs for inline embedding, reducing HTTP requests.
- Transfer files via JSON APIs: Encode PDFs, documents, or images as Base64 strings to include them in JSON payloads.
- Encode credentials: Base64-encode username:password pairs for HTTP Basic Authentication headers.
- Debug encoded data: Decode Base64 strings from API responses, logs, or configuration files to inspect the original content.
- Data URI generation: Create ready-to-use
data:image/png;base64,β¦URIs for web development.
Encoding Text vs. Binary Files
For text encoding, the tool uses JavaScript's built-in btoa() function, which converts a string to its Base64 representation. This works for plain text, JSON, XML, and any other text-based content. Simply type or paste your text into the input box and click Encode.
For binary files (images, PDFs, zip archives, etc.), use the file upload button. The file is read using the browser's FileReader API as a binary string, then encoded to Base64. After encoding, you can copy the full Base64 string or download it as a .txt file. For images, the tool can optionally generate a complete data URI that you can paste directly into an <img> tag's src attribute.
Decoding Base64 Strings
Switch to Decode mode to convert a Base64 string back to its original form. The tool uses atob() for decoding. If the decoded result is valid UTF-8 text, it will be displayed directly in the output area. For binary data, you can download the decoded bytes as a file. The tool automatically detects whether the decoded content is text or binary and presents the appropriate output format.
Keyboard Shortcuts
For faster workflow, press Ctrl+Enter (or Cmd+Enter on Mac) while the input field is focused to trigger the current mode's primary action β encoding in Encode mode or decoding in Decode mode. This saves you from reaching for the mouse and speeds up batch processing.
Is Base64 Encryption?
No. Base64 is encoding, not encryption. It provides no security whatsoever β anyone can decode a Base64 string back to its original form instantly. Base64 is purely a data representation format designed to ensure binary data can be safely transmitted through systems that only support text. If you need to protect sensitive data, use proper encryption algorithms such as AES-256 or RSA. Never rely on Base64 encoding for security.
π‘ Pro Tips
- Data URIs for one-off images: Upload a small icon or logo, encode it, and paste the resulting
data:image/png;base64,β¦URI directly into your HTML or CSS. No separate image file needed β great for email signatures and single-page demos. - Decode JWT payloads instantly: A JSON Web Token's payload is just Base64. Copy the middle segment (between the two dots), paste it into Decode mode, and you'll see the claims in plain text β no library needed.
- Spot the difference between Base64 and Base64URL: If your Base64 string has
-and_instead of+and/, it's Base64URL (used in JWTs and URL-safe contexts). Replace-β+and_β/before decoding. - Debug HTTP Basic Auth headers: A Basic auth header value is just Base64-encoded
username:password. Paste it β minus the leading scheme word β into Decode mode to see the credentials in plain text: useful when debugging API calls or checking exactly what your HTTP client is sending. - Recognize file types by their Base64 header: Many common formats have distinctive Base64 prefixes.
iVBORw0KGgo= PNG image,/9j/= JPEG,JVBERi0= PDF,UEsDBBQ= ZIP archive. Paste the first 20 characters into Decode mode and look at the raw bytes to identify an unknown Base64 blob without fully decoding it. - Send binary data through JSON APIs: JSON is text-only, so any binary field β an uploaded image, a digital signature, a file blob β must be encoded before it can travel in a request body. Base64 is the de facto standard:
btoa()on the client,Buffer.from(str, 'base64')on the Node.js side. Mind the β33% size overhead and compress large payloads before encoding.
Why Does My Chinese/Emoji Text Encode Incorrectly?
Base64 operates on bytes, not characters. When you paste Unicode text (Chinese, Japanese, emoji, or any non-ASCII characters), the browser internally converts the string to UTF-8 bytes before encoding. This tool handles that automatically via btoa(unescape(encodeURIComponent(text))), which first encodes the string as a URI-escaped UTF-8 byte sequence, then unescapes each byte, then applies Base64. This means "δ½ ε₯½" correctly encodes to "5L2g5aW9" β not the garbled result you'd get from calling btoa() directly on a non-Latin1 string. If you're implementing Base64 in your own code, remember this extra step or use TextEncoder in modern JavaScript.
Can I Encode Large Files?
Yes β this tool processes files entirely in your browser's memory using the FileReader API. For most use cases (images under 10 MB, documents, small archives), performance is instant. Very large files (50 MB+) may cause brief browser lag since the entire file must be read into RAM for encoding. If you're working with large binaries regularly, consider a native command-line tool like base64 on Linux/macOS or certutil -encode on Windows. For everyday developer tasks β embedding icons, encoding API credentials, or inspecting JWT payloads β the browser-based tool is more than sufficient.
Why Does My Base64 String End With = or ==?
Those trailing equals signs are padding characters. Base64 encodes every 3 bytes of input into 4 Base64 characters. When your input length in bytes isn't divisible by 3, the encoder adds padding: one = for 1 extra byte (e.g., a 4-byte input β 8 Base64 chars + ==), and two = for 2 extra bytes. This ensures the output length is always a multiple of 4 β a requirement for most Base64 decoders. Some implementations (Base64URL, raw Base64) omit padding, and this tool handles both padded and unpadded strings without issues.
Why Does My Base64 String Have Line Breaks β and Why Won't It Decode?
Base64 produced by email systems, PEM certificate files, and several language runtimes is wrapped: a newline is inserted every 64 or 76 characters (RFC 2045 specifies 76) so the text survives line-length limits in older text protocols. Most decoders tolerate that whitespace, but a few strict ones reject it outright β Java's Base64.getDecoder() throws IllegalArgumentException (use getMimeDecoder() instead), and Go's base64.StdEncoding.DecodeString() fails with illegal base64 data at input byte 64. The fix is to strip all whitespace before decoding: re.sub(r'\s+', '', s) in Python, or s.replace(/\s/g, '') in JavaScript. This tool ignores line breaks, spaces, and tabs automatically, so wrapped output from openssl base64, a PEM block, or a MIME email body decodes without manual cleanup.
How to Encode Images for Email Signatures
Base64-encoded images are perfect for email signatures because they eliminate the need for external image hosting. Simply upload your logo or headshot, click Encode, and copy the generated data:image/png;base64,β¦ URI. Paste it as the image source in your email client's signature editor. The image is embedded directly in the email body β no broken image links when recipients open the email offline, and no dependency on an external CDN that might change or go down. Note that some email clients (notably older Outlook versions) don't render Base64 images, so include alt text as a fallback.
How to Base64-Encode SVG Icons for CSS Backgrounds
SVG icons encoded as Base64 data URIs make excellent CSS background images β no extra HTTP requests, no sprite sheets, and they scale perfectly at any resolution. Paste your SVG markup into the Encode tab, copy the output, and use it as background-image: url("data:image/svg+xml;base64,..."). For best results, optimize your SVG first with SVGO to strip unnecessary metadata and keep the encoded string compact.
Quick Tip: Encoding from the Terminal
If you're on macOS or Linux, you can Base64-encode any file with a single command: base64 -i input.png -o output.txt (or pipe with cat file.png | base64). To decode: base64 -d encoded.txt > original.png. This is faster than uploading through a browser for large batches, though our web tool is more convenient for quick one-off conversions and data URI generation.
Why Is Base64 Output About 33% Larger Than the Original?
Because Base64 is a representation format, not compression. It packs 3 bytes of input into 4 text characters, so the output is always 4/3 the size of the input β about 33% bigger. That overhead is the price you pay for making binary data safe to transmit through text-only channels (JSON payloads, URLs, email bodies). This is also why embedding a large image as a data: URI bloats your HTML: a 300 KB photo becomes a ~400 KB string. If size matters, compress the image first, then encode β or skip Base64 entirely and serve the file from a CDN.
How to Encode/Decode Base64 in Node.js and Python
When you need Base64 in your own code rather than in the browser, both major backends make it a one-liner. In Node.js, encode text with Buffer.from(text).toString('base64') and decode with Buffer.from(encoded, 'base64').toString('utf8'). For binary files, read them into a Buffer first β e.g. fs.readFileSync('image.png') β then call .toString('base64') on that Buffer directly.
In Python, the standard-library base64 module covers it: base64.b64encode(data).decode('ascii') encodes bytes (the .decode() step gives you a str ready for JSON payloads), and base64.b64decode(encoded) reverses it. Base64 operates on bytes, so encode strings to UTF-8 first β 'δ½ ε₯½'.encode('utf-8') in Python, or new TextEncoder().encode(text) in Node β or non-ASCII text will come out garbled. For URL-safe contexts (query params, JWTs), both languages offer dedicated variants: Buffer.from(data).toString('base64url') in Node and base64.urlsafe_b64encode() in Python swap +// for -/_ and drop the trailing = padding.
How Do I Decode a data: URI Like data:image/png;base64,β¦?
A data: URI is not Base64 β it is a MIME type, then a comma, and then the Base64 payload: data:image/png;base64,iVBORw0KGgoβ¦. Paste the whole string into a decoder and it fails, because everything before the comma is plain text, not Base64. Strip up to and including the first comma and decode what remains. Two variants to watch for: an unencoded data URI (data:text/plain,Hello) carries no ;base64 marker and is already plain text, so decoding it is meaningless; and SVG data URIs are sometimes percent-encoded (%3Csvgβ¦) rather than Base64. In code, split on the comma exactly once β payload = uri.split(',', 1)[1] in Python β then decode only that part. If the decode still fails, the payload itself may be Base64URL (-/_) or carry line breaks.
Why Does My Decoded Text Come Out as Garbled Characters (ΓΒ©, Γ¦Λβ, ΓΒ€)?
Because Base64 encodes bytes, and something on the way back is turning those bytes into text with the wrong character set. The classic signature: Γ© (UTF-8 bytes c3 a9) shows up as ΓΒ©, Chinese shows up as Γ¦Λβ, and both look like a font problem but are not. Two bytes were correctly decoded and then interpreted as Latin-1 / Windows-1252 instead of UTF-8, so each of the two UTF-8 bytes became its own character. This happens most often when a server does atob(s) (or Python b64decode(s).decode('latin-1')) instead of decoding the bytes as UTF-8, and when a database or HTTP header says charset=iso-8859-1. The fix is to keep the byte layer explicit: in Node Buffer.from(encoded, 'base64').toString('utf8'), in Python base64.b64decode(encoded).decode('utf-8'). Never round-trip through latin-1 "to be safe" β that is exactly what creates the mojibake. If the damage is already done, the text is theoretically recoverable by re-encoding the garbled string to Latin-1 bytes and decoding those as UTF-8, but only if nothing was lost in between.
Why Does My Decoder Return Empty Output Instead of an Error?
Because most Base64 decoders are deliberately lenient, and leniency hides corruption. Node ignores every character outside the alphabet: Buffer.from('!!!!', 'base64') returns a zero-length buffer with no exception, and Buffer.from('aGVs bG8=', 'base64') happily returns hello after dropping the space. Python behaves the same way with validate=False (the default) β base64.b64decode('!!!!') returns b''. The two runtimes also disagree on padding: Node accepts unpadded input (aGVsbG8 β hello), while Python raises binascii.Error: Incorrect padding and needs encoded + '=' * (-len(encoded) % 4). So "it decoded to nothing" or "it decoded but the bytes are wrong" usually means the string was truncated, pasted with markup, or was never Base64 to begin with. Validate before decoding: strip whitespace, check the input matches ^[A-Za-z0-9+/]*={0,2}$ (or the -/_ URL-safe variant), and pass validate=True in Python when you want a real exception instead of silence.
How to Use This Tool
Using the Base64 tool is simple. For encoding: type or paste your text, or upload a file, then click Encode (or press Ctrl+Enter). The Base64 output appears below, ready to copy or download. For decoding: switch to Decode mode, paste a Base64 string, and click Decode. The tool handles both padded and unpadded Base64 strings automatically.