Base64 Encode / Decode

Encode text or files to Base64, or decode Base64 back to text — UTF-8 safe, with URL-safe output, all in your browser.

1 Type or paste — text to encode, or Base64 to decode

2 Result — copy it, or use it as a code snippet

Code-snippet templates

3 Decode back to a file — paste Base64 in step 1, or pick a file that contains it

Base64 often hides a file — an image, a PDF, a ZIP. This downloads the original bytes back, with the file type detected from the data itself. Images get a preview here, so you can see what you are about to save.

4 Or encode a file — the snippet in step 2 updates to match it

Choose any file to get its Base64 representation — the same format used to embed images in HTML and CSS, and to attach files to JSON APIs.

5 Or encode several files at once — each file gets its own row

Select multiple files to encode them all in one go. Each file gets its own row with its Base64 string, a Copy button and a Download .txt button — if one file cannot be read, only its row shows an error and the rest still encode.

    What is Base64?

    Base64 is a way of writing binary data — or any text — using only 64 safe characters: A–Z, a–z, 0–9, plus (+) and slash (/), with equals (=) as padding. It exists because many systems only handle plain text safely: email, URLs, JSON, HTML and CSS all have characters that break things, and binary data is full of them. Base64 takes any bytes, groups them into threes, and rewrites each group as four text characters. The result is plain ASCII that survives email, JSON and URLs untouched, at the cost of making the data about a third larger.

    You have seen Base64 without knowing it. The data:image/png;base64,… string that embeds an image directly in a web page is Base64. The long token in an email header is Base64. The credentials in a basic-auth header (Authorization: Basic dXNlcjpwYXNz) are just “user:pass” in Base64 — which is why basic auth is only safe over HTTPS: Base64 is an encoding, not encryption, and anyone can decode it in a second. That distinction is the most important thing to understand about this tool: encoding is not encrypting. Base64 hides nothing.

    This tool encodes and decodes text with full UTF-8 support, so emoji and non-English text survive the round trip — something the browser’s built-in functions get wrong on their own. It also encodes files: pick any file and get its Base64 form, ready to paste into HTML, CSS or a JSON request. And it works the other way too: paste Base64 that hides a file and download the original back, with the file type detected and images previewed. If a pasted string will not decode, the tool explains what is wrong — a bad character, a missing pad, a length that cannot be valid — and offers to repair it.

    How to encode and decode Base64

    1. To encode: type or paste text into the box and click “Encode to Base64”. Tick “URL-safe output” if the result goes into a URL or a filename — it swaps + and / for - and _ and drops the padding. Tick “Wrap output at 76 characters” only if the format you are pasting into (email, MIME) asks for wrapped lines.
    2. To decode: paste a Base64 string and click “Decode from Base64”. The tool checks the string first and explains the problem if it is not valid — and offers to repair it when it can.
    3. To get a file back: if the Base64 hides an image, a PDF or another file instead of text, use “Download decoded file” in step 3. The file type is detected from the data, images are previewed before you save, and you can rename the file first.
    4. To encode a file: use the file picker in step 4. The file’s Base64 appears in the box, ready to copy — and the snippet in step 2 updates to match it, so you can copy a ready-to-paste data URI, CSS rule or HTML tag.
    5. Copy the result with the Copy button. The output is plain text — paste it anywhere.

    Encoding several files at once: use the second file picker, below the single-file one, and select as many files as you like. Each file is encoded separately and gets its own row showing its filename, its size, a preview of its Base64 string, a Copy button for the full string, and a Download .txt button that saves the Base64 as a text file named after the original (for example logo.png.b64.txt). If one file cannot be read, only that row shows an error — the other files still encode. As with a single file, everything is read in your browser and nothing is uploaded.

    Three everyday uses

    1. Embedding a small image in HTML or CSS

    A tiny icon or logo as a separate file means an extra request every time the page loads. Embed it as a data URI — url(data:image/png;base64,…) — and the image travels inside the stylesheet itself. That is the right call for icons under a few kilobytes; for large photos it is not, because Base64 makes the file a third bigger and the browser cannot cache it separately. Use the file encoder in step 4 to get the string, then pick “CSS background-image” or “Data URI” in the snippet box in step 2 to copy a ready-to-paste version — no hand-assembly needed.

    2. Sending data through JSON APIs

    JSON is text, so binary data cannot go in it raw. APIs that accept a file as part of a JSON request expect Base64: the client encodes the file, the server decodes it. The same pattern shows up in email (MIME attachments are Base64) and in configuration files that need to carry a certificate or a small binary blob as text.

    3. Reading a token or a header

    Basic-auth headers, JWT tokens and many API keys are Base64 under the surface. Paste the token’s middle section here and decode it to see the JSON claims inside a JWT — who it was issued to, when it expires, what it allows. That is also why you should never paste a live production token into a server-side decoder: this one runs locally, so the secret never leaves your machine.

    Common mistakes to avoid

    • Treating Base64 as encryption. It is not. Anyone can decode Base64 in a second, including the person you are hiding the password from. Never use it to “protect” a secret — use real encryption, or just HTTPS.
    • Breaking the string across lines. Base64 is one continuous string, and many strict decoders reject a line break in the middle or a missing = at the end. This tool strips line breaks and repairs missing padding for you — but only turn on the 76-character wrap when the format you are pasting into actually asks for wrapped lines.
    • Using standard Base64 in a URL. The + and / characters have special meanings in URLs. Tick “URL-safe output” for anything that goes in a link, a query string or a filename.
    • Encoding large files. Base64 adds about 33% to the size. A 10 MB file becomes 13.3 MB of text, which is slow to copy, slow to send, and often over the limit of whatever you are pasting it into. For large files, upload the file instead of encoding it.
    • Forgetting UTF-8. The browser’s built-in btoa() only handles Latin-1 text and throws an error on emoji or Chinese characters. This tool encodes as UTF-8 first, so any text survives the round trip.

    Frequently asked questions

    Is Base64 encryption?
    No. It is an encoding — a different way of writing the same data, not a way of hiding it. Anyone can decode Base64 instantly. Never use it to protect a password or a secret.
    Why is the encoded output longer than the input?
    Base64 represents every 3 bytes as 4 characters, so the output is about 33% larger than the input, plus up to two = padding characters. That is the price of using only safe text characters.
    What is URL-safe Base64?
    Standard Base64 uses + and /, which have special meanings in URLs, and = padding, which can confuse query strings. URL-safe Base64 replaces + with -, / with _, and drops the padding. It decodes to exactly the same data.
    Why does decoding fail with “invalid character”?
    The string contains something outside the Base64 alphabet, or it has the wrong length. Common causes: a line break in the middle, a missing = at the end, or a character copied from a formatted document — a smart quote, a dash, or a space.
    Can I decode Base64 back to a file?
    Yes — paste the Base64 in step 1 and use “Download decoded file” in step 3. The file type is detected from the data itself (PNG, JPEG, GIF, WebP, SVG, PDF, ZIP and more), images are previewed before you save, and you can rename the file first. You can also pick a .txt file that contains Base64 and decode it straight to a download.
    What does the 76-character wrap do?
    It breaks the encoded output into lines of 76 characters, the format email (MIME) expects. Most modern uses want one unbroken string, so the wrap is off by default — turn it on only when the format you are pasting into asks for wrapped lines.
    Can I encode a file here?
    Yes — use the file picker at the bottom of the tool. The file is read in your browser and encoded locally, so the contents never leave your computer. Keep files small: a few megabytes at most, because the text output is a third larger than the file.

    Privacy

    Encoding and decoding happen entirely in your browser. Tokens, keys and file contents are never sent to a server. Close the tab and they are gone.

    Worked example: reading a JWT token

    A JWT — the token format most APIs use for login — has three parts separated by dots: header, payload, signature. The first two are Base64 (URL-safe). Take a token like eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c and paste the middle section — eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ — into this tool and decode it. The result is readable JSON: {"sub":"1234567890","name":"John Doe","iat":1516239022}. The iat value is a Unix timestamp, which you can check with the Timestamp Converter on this site — it is 18 January 2018. That round trip, from an opaque token to a readable claim, is the most useful Base64 decoding most developers ever do.

    The warning that goes with it: anyone can do this. The payload of a JWT is encoded, not encrypted, so never put anything sensitive in it — no passwords, no personal data, nothing you would mind a stranger reading. The signature is what makes a JWT trustworthy, not the encoding: the server checks the signature against its secret, and a token with a forged payload fails that check. Decoding tells you what the token claims; only the server can tell you whether the claim is true.

    How much bigger does Base64 make things?

    Original sizeBase64 sizeOverhead
    3 bytes4 characters+33%
    1 KB~1.37 KB+33%
    100 KB~137 KB+33%
    1 MB~1.37 MB+33%

    The overhead is constant at about a third, whatever the size — which is why Base64 is fine for tokens and small images and a bad idea for large files.

    Share this tool

    Copy the link below and paste it anywhere — a chat message, an email, a document. Whoever opens it gets the same free tool, with no account and nothing to install.

    Related tools