Skip to main content

    Base64 Encoder & Decoder

    Encode text to Base64 or decode Base64 back to text. Supports UTF-8 and Unicode.

    Free to use. Runs in your browser.

    Paste text or a file and click Encode to get Base64 output, or paste Base64 and click Decode to recover the original. Works offline, your data never leaves your browser.

    Use Base64 for transport formats such as JSON, email, and data URIs, not for hiding secrets.

    What Is Base64 and When Do You Need It?

    Base64 is a way of representing binary data using only text characters. It converts raw bytes into a string of letters, numbers, plus signs, and slashes, characters that survive being passed through systems that only handle text (like email, JSON, or HTML).

    Think of it like spelling out a phone number in words: "oh-seven-seven-oh" instead of 0770. The information is the same, just represented in a text-safe format. The trade-off? Base64 output is about 33% larger than the original data. That's the cost of text-safety.

    Important: Base64 is encoding, not encryption. Anyone can decode it instantly. Never use Base64 to "hide" passwords, tokens, or sensitive data, it provides zero security.

    Common Base64 Use Cases

    Use CaseWhy Base64?Example
    Data URIs in HTML/CSSEmbed small images directly in code<img src="data:image/png;base64,...">
    Email attachments (MIME)SMTP only handles 7-bit ASCII textContent-Transfer-Encoding: base64
    JSON payloadsJSON can't contain raw binary{"file": "SGVsbG8..."}
    JWT tokensHeader and payload are Base64URL encodedeyJhbGciOiJIUzI1NiJ9...
    HTTP Basic AuthCredentials encoded (not encrypted!)Authorization: Basic dXNlcjpwYXNz
    SVG in CSSInline SVG backgrounds without extra requestsbackground: url("data:image/svg+xml;base64,...")

    What this means for you: If you're embedding small icons (under 2KB) in CSS, Base64 data URIs save HTTP requests. For anything larger, a regular image file with proper caching is more efficient.

    Base64 vs Other Encodings

    EncodingCharacters UsedSize OverheadBest For
    Base64A-Z, a-z, 0-9, +, /+33%Binary data in text contexts
    Base64URLA-Z, a-z, 0-9, -, _+33%URLs, JWTs (no +/= characters)
    Hex0-9, a-f+100%Hash digests, colour codes
    URL encoding%XX formatVariableSpecial characters in URLs

    Common Base64 Mistakes

    Mistake

    Using Base64 for "security". Base64 is trivially reversible. Encoding a password or API key in Base64 provides zero protection. Use proper encryption (AES) or hashing (bcrypt) for sensitive data.

    Mistake

    Base64-encoding large images in CSS. A 50KB image becomes 67KB as Base64, and it can't be cached separately from the stylesheet. Only inline images under 2KB, anything larger should be a regular file with HTTP caching.

    Mistake

    Mixing Base64 and Base64URL. Standard Base64 uses + and / which break in URLs. JWTs use Base64URL (with - and _ instead). Decoding one with the other's alphabet produces garbage. Check which variant you need.

    How to Read Base64 Output

    Base64 output looks random, but it has a strict structure. Each group of four Base64 characters represents three original bytes. Padding with = appears only at the end, and only when the input length is not divisible by three.

    InputBytesBase64What to Notice
    f1Zg==Two padding characters because only one byte was available
    fo2Zm8=One padding character because two bytes were available
    foo3Zm9vNo padding because the input filled a full three-byte group
    Hello5SGVsbG8=The final = shows that the last group had two input bytes

    Padding is not extra data. It tells the decoder how many bytes to recover from the final four-character group.

    If padding is missing, restore it only at the end of the string, never in the middle.

    Validating a Base64 String

    Check the alphabet

    Standard Base64 should contain only letters, digits, +, /, and trailing = padding. Whitespace is sometimes wrapped into long MIME output, but it is not part of the encoded data.

    Check the length

    A padded Base64 string should have a length divisible by four. If it does not, it may be missing padding or may be Base64URL from a token or URL-safe format.

    Check the variant

    A JWT segment usually uses Base64URL, so it may contain - and _ instead of + and /. Convert the alphabet before using a strict standard Base64 decoder.

    Check the decoded bytes

    Decoding can succeed even when the result is not readable text. Images, PDFs, ZIP files, and encrypted blobs are binary data, so inspect them with the right file tool.

    Base64 in Data URIs

    A data URI combines a media type, an optional charset, and the encoded payload. The browser treats it like an inline file. This is useful for tiny assets, but it is a poor fit for large images because the encoded text grows and cannot be cached as a separate resource.

    data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==

    PartMeaning
    data:Signals that the URL contains inline data rather than an external address
    image/svg+xmlDeclares the MIME type so the browser knows how to interpret the bytes
    ;base64Declares that the payload is Base64 encoded
    ,Separates metadata from the encoded payload

    Encoding Text Correctly

    Plain ASCII examples are simple, but real text often includes accents, symbols, right-to-left scripts, or emoji. JavaScript's old btoa() function expects byte-style Latin-1 text, so direct encoding can fail for characters outside that range.

    TextEncoding DetailWhy It Matters
    cafeASCII letters onlyOne byte per character
    caféMay include a combining accentLooks similar, but byte length can differ
    東京UTF-8 uses three bytes per characterNeeds byte-aware encoding before Base64
    🌍UTF-8 uses four bytesOld ASCII-only snippets fail on emoji

    This page uses TextEncoder and TextDecoder so Unicode text is converted through UTF-8 bytes first.

    Practical Debugging Checklist

    If decoding fails

    Look for copied quotes, missing padding, line wrapping, or a URL-safe alphabet. A common fix for JWT segments is to replace - with +, replace _ with /, then restore padding to a multiple of four.

    If output looks broken

    The decoded bytes may not be UTF-8 text. Try saving the bytes as the expected file type, or inspect the first bytes for file signatures such as PNG, PDF, ZIP, or GIF.

    If the payload is too large

    Prefer a file upload, object storage URL, or streaming transfer. Large Base64 strings are harder to diff, harder to cache, and can make JSON payloads expensive to parse.

    Related Tools

    How to use this tool

    1

    Enter text or Base64 string in the input

    2

    Click Encode or Decode

    3

    Copy the result or swap input/output

    Common uses

    • Embedding small images in HTML/CSS as data URIs
    • Encoding binary data for JSON payloads
    • Decoding JWT token components
    • Preparing email attachments for MIME transport
    • Converting files for inline SVG backgrounds

    Share this tool

    Frequently Asked Questions

    What is Base64 encoding?
    Base64 is a binary-to-text encoding scheme that represents binary data using only ASCII characters (A-Z, a-z, 0-9, +, /). It's how email attachments travel through SMTP, how small images get embedded in CSS, and how JWT tokens encode their header and payload. The trade-off is a 33% size increase.
    Is Base64 encryption?
    No, and this is a critical distinction. Base64 is encoding, not encryption. Anyone can decode it instantly with zero effort. Never use Base64 to 'hide' passwords, API keys, or sensitive data. It provides exactly zero security. Use it for data transport only.
    Does this tool support Unicode and emojis?
    Yes. We use TextEncoder/TextDecoder to properly handle UTF-8 characters, including emojis, CJK characters, Arabic, and other non-Latin scripts. Standard btoa() breaks on Unicode, our implementation handles it correctly.
    What's the difference between Base64 and Base64URL?
    Standard Base64 uses + and / characters, which have special meaning in URLs. Base64URL replaces them with - and _ and removes padding (=). JWTs use Base64URL, not standard Base64. This tool uses standard Base64 encoding.
    Why does Base64 make data 33% larger?
    Base64 converts every 3 bytes of input into 4 ASCII characters. Three bytes = 24 bits, divided into four 6-bit groups, each mapped to one of 64 characters. That 4/3 ratio means roughly 33% size overhead, the cost of text-safety.
    When should I use Base64 data URIs vs regular images?
    Use Base64 data URIs for tiny images under 2KB, icons, simple SVGs, 1x1 tracking pixels. For anything larger, a regular image file with proper HTTP caching is more efficient. A 10KB image becomes ~13.3KB in Base64 and can't be cached separately.
    How do I Base64 encode in JavaScript?
    For ASCII text: btoa('hello') gives 'aGVsbG8='. For Unicode: use TextEncoder to get bytes first, then btoa(). To decode: atob('aGVsbG8=') returns 'hello'. Node.js uses Buffer.from('hello').toString('base64') instead.
    Can I encode files and images to Base64?
    This tool encodes text to Base64. For files and images, you'd use FileReader.readAsDataURL() in JavaScript, or the command line: base64 image.png on macOS/Linux, or [Convert]::ToBase64String() in PowerShell.
    What characters are valid in Base64?
    Standard Base64 uses 64 characters: A-Z (26), a-z (26), 0-9 (10), + and / (2), plus = for padding. If your Base64 string contains any other character, it's invalid and will fail to decode.
    Why is Base64 used in email (MIME)?
    SMTP (email protocol) was designed for 7-bit ASCII text only. Binary attachments, images, PDFs, zip files, can't survive the journey. Base64 converts them to text that SMTP can handle, then the recipient's email client decodes them back.
    Is my data sent to a server?
    No. All encoding and decoding happens entirely in your browser using JavaScript's built-in btoa() and atob() functions. Your data never leaves your device, check the network tab in DevTools if you want proof.
    What's the maximum size I can encode?
    There's no hard limit in this tool, but browsers have practical limits. Current browsers handle strings up to several hundred MB. For very large files, use a streaming encoder or command-line tool instead.

    Results are for general informational purposes only and should be checked before use. They are not professional advice. See our Disclaimer and Terms of Service.