Layerbit
Runs entirely in your browser

Base64 Encoder & Decoder

Encode and decode Base64 in real time — text or files of any size, standard or URL-safe, one line or MIME and PEM wrapped, in UTF-8, UTF-16 or Windows-1252 — and see what decoded bytes really are, with a hex view, without your data leaving the browser.

Plain Text
Invalid Base64 String
Base64 Encoded
File to Base64
Base64 to file
Invalid Asset Data
Rendered Preview

What this Base64 tool does

This page encodes text and files to Base64 and decodes Base64 back, as you type. Use it to put binary data into JSON or XML, embed a small image in CSS or HTML as a data URI, read the payload of a webhook or an email attachment, or check what a Base64 string really contains. Everything happens in your browser; nothing is sent to a server.

API Payload Transmission

When building full-stack web applications, especially within robust backend architectures like .NET, transporting raw binary files over JSON REST APIs can be complex. Converting binary streams into a Base64 string allows seamless serialization directly into standard JSON payloads for easier data transit.

Data URI Asset Embedding

Reduce HTTP requests on landing pages by converting lightweight icons, logos, or placeholder graphics into Base64 Data URIs. You can paste the resulting string directly into an HTML `<img src="...">` tag or as a CSS background-image.

JWT & Token Debugging

JSON Web Tokens (JWTs) are heavily reliant on Base64Url encoding. Use the Text tab to decode the payload section of authentication tokens to verify embedded user claims, expiration dates, and roles without needing specialized third-party tools.

Quick Testing Templates

Want to see it work? Click a sample below to load it and watch the conversion happen as it loads.

Image to Base64, and Base64 back to an image

To convert an image to Base64, open the Files & images tab and drop a PNG, JPG, SVG, WebP, GIF or PDF on the left pane. The result is a data URI you can paste straight into HTML or CSS:

WhereHow to use the result
HTML<img src="data:image/png;base64,iVBORw0KGgo..." alt="Logo">
CSSbackground-image: url("data:image/svg+xml;base64,PHN2Zy...");
JSON or an APISend only the part after the comma, and put the type (image/png) in its own field.
Email (MIME)Choose MIME (76 per line) wrapping, which mail systems expect.

To turn Base64 back into an image, paste a data URI such as data:image/png;base64,... into the right pane. The image (or PDF) is shown at once, and Download saves it with the right extension. For Base64 without the data: prefix, paste it into the Text tab: the decoded bytes are recognised from their first bytes (PNG, JPEG, GIF, PDF, ZIP and more), shown in a hex view, and saved with Download bytes.

Base64 makes a file about 33% larger, so embed only small images such as icons and logos (a few kilobytes). Larger images load faster as normal files, because the browser can cache them and fetch them in parallel.

Frequently Asked Questions

Base64 is a binary-to-text encoding scheme that translates arbitrary binary data (like images, PDFs, or compiled code) into an ASCII string format. It translates the data into a radix-64 representation, using only 64 specific characters (A-Z, a-z, 0-9, +, and /) ensuring the data remains intact without modification during transport across systems that only support text.

No. This is a very common misconception. Base64 is strictly an encoding mechanism used for data translation and transport, not a security protocol. It does not use cryptographic keys, and anyone with access to the Base64 string can instantly decode it back to its original format. Never use Base64 to hide sensitive data or passwords.

Because Base64 uses a limited character set to represent binary data, it requires 4 standard ASCII characters to represent every 3 bytes of raw data. This mathematical conversion means that encoding any file into Base64 will automatically increase its overall size by approximately 33%. This is why it is best used for small assets rather than massive video or audio files.

Email (MIME, RFC 2045) limits Base64 lines to 76 characters, and PEM files such as certificates and private keys (RFC 7468) use 64. Many tools expect those exact widths, and some refuse a single long line. Choose the width under the Base64 box or in the file panel; lines end with CRLF as both standards require. The decoder ignores line breaks and spaces, so wrapped input of any width decodes as is.

Paste it into the Base64 box. Below the editors the tool shows the decoded size, the file type recognised from the first bytes (the "magic number", such as 89 50 4E 47 for PNG or 25 50 44 46 for PDF), and a hex view of the first 256 bytes. Download saves the bytes with the matching extension. Text is decoded with the encoding you pick: UTF-8, UTF-16 or Windows-1252. Bytes that are not valid UTF-8 are shown one character per byte rather than as replacement characters.

Yes. Files are read and encoded in 4 MB slices into a downloadable file, so a 100 MB+ video or disk image never has to exist as one giant string in memory. Files up to 8 MB are also shown as a data URI you can copy. "Decode a Base64 file" works the same way in reverse and names the result from its detected type. Everything happens in this page; nothing is uploaded.

How the encoding works, and what it costs

Base64 (RFC 4648) regroups every three bytes of input — 24 bits — into four 6-bit chunks, each of which indexes a 64-character alphabet. Three bytes in, four characters out, which fixes the overhead at exactly 33% regardless of content. A 3 MB image becomes a 4 MB data URI, and the encoded form compresses worse than the original binary did.

That ratio is the main thing to know when deciding whether to inline an asset. Replacing one HTTP request with a third more bytes on every page load is often the wrong trade, and it is always worth measuring rather than assuming. Our Base64 guide goes into the arithmetic, the padding rules and the URL-safe variant in full.

What the = is for

Padding. When the input is not a multiple of three bytes the output is padded to a multiple of four: one leftover byte gives two characters plus ==, two leftover bytes give three plus =. It carries no data — it only tells a streaming decoder where the input ended.

Why URLs need a variant

Standard Base64 uses + and /. In a query string, form decoding turns + into a space; in a path, / is a separator. Base64url substitutes - and _ and usually drops the padding, which is why JWT segments look the way they do.

Bytes, not text

Base64 encodes bytes. To encode a string you must first choose how it becomes bytes — almost always UTF-8. The browser's btoa() predates this and throws on any character above U+00FF, so accented letters, CJK text and emoji all fail without a TextEncoder step first.

It is an encoding, not a protection

Base64 has no key, no secret and no variability: the same input always produces the same output, and every decoder on earth reverses it instantly. It is worth being blunt about this because the mistake is so common and so consequential.

  • HTTP Basic authentication sends base64(user:password). Over plain HTTP that is a password in clear text — the encoding changes nothing an attacker cares about.
  • Kubernetes Secrets store values Base64-encoded, which makes them look protected in a manifest. They are not encrypted, and by default they are not encrypted at rest in etcd either.
  • Encoding a credential in a config file, a cookie or a mobile app bundle makes it marginally less obvious to a casual reader and no harder at all to recover.

If you need confidentiality you need encryption. If you only need to move bytes through a text-only channel, Base64 is exactly the right tool — and those are genuinely different problems.

Why decoding here is local

The Base64 strings developers most often need to decode are the interesting ones: a token from a log file, a credential from a misconfigured header, a certificate body, an encoded payload from a bug report. Pasting those into a server-side decoder means handing the underlying secret to someone else's infrastructure. This tool runs entirely in the page — text and file input alike — so whatever you decode stays on your machine.

Changelog

  • v2.0.0 MIME (76 characters) and PEM (64) line wrapping. Text encodings: UTF-8 with or without a BOM, UTF-16 LE and BE, and Windows-1252, both ways. Decoded bytes show their file type from their magic bytes (PNG, PDF, ZIP, DOCX, MP4, WebAssembly and about 40 more), a hex view, and download with the right extension; an invalid string says which character, at which position. Files of any size are encoded and decoded in slices, so a 100 MB+ file never becomes one giant string, and a file whose bytes disagree with its declared type is flagged.
  • v1.5.0 A line-endings option: text can be encoded with CRLF line breaks, as a Windows file stores them.
  • v1.4.1 Added a URL-safe output toggle (RFC 4648 §5 alphabet, no padding) and a live byte/character readout, so the 33% overhead is visible on the input you actually have.
  • v1.4.0 Decoder now accepts the URL-safe alphabet (- and _), ignores line wrapping and whitespace, and tolerates missing padding, so JWT segments and copied-from-a-log strings decode directly. Encoding and decoding use TextEncoder/TextDecoder for correct UTF-8 on multi-megabyte input.
  • v1.3.0 Added deep clipboard API integration with a safe fallback mechanism for mobile devices handling massive image strings.
  • v1.2.0 Integrated visual asset rendering for Data URIs, allowing real-time preview of encoded images and PDF iframes.
  • v1.1.0 Implemented native DOM parsing for bidirectional, real-time string synchronization.