Waiting for input

Input

Output

 

The result appears here as you type.

    Ctrl+Enter run / or Ctrl+K search tools Press Ctrl+D to bookmark this page

    How to decode Base64

    1. Paste the Base64 into the Input box, or drop a file that contains it. Decoding starts as you type.
    2. Read the result. Text appears as text. Images, archives and other binary data appear as hex, and images also get a preview below.
    3. Check the summary: it says which alphabet and padding the input used and lists everything that was removed before decoding.
    4. Copy the text, or download the data. The download is named after the type found in its first bytes.

    Need the other direction? Press Encode, or open the Base64 encoder.

    What is cleaned before decoding

    • Line breaks and spaces, as in MIME email parts and PEM certificates.
    • One pair of quotes around the whole value, as when you copy a string out of JSON or code.
    • A data URL prefix such as data:image/png;base64,. Its declared type is kept and compared with the real one.

    Each removal is listed, with a count. Nothing else is dropped: any other character that is not Base64 stops decoding with a message that names it.

    Understanding decode errors

    • Not a Base64 character: the message gives the line and column in your input, as you see it, and highlights the character there. If line breaks or a prefix were removed before it, it also gives the position in the cleaned Base64. A dot usually means a JWT; a % sign means URL-encoded text.
    • Wrong length: Base64 comes in groups of 4 characters, so a last group of 1 is impossible. A character was lost or added, often when copying.
    • Padding in the middle: = may only come at the end. This usually means two Base64 values were joined; decode them separately.
    • Padding where none is needed or too much padding: the number of = signs does not fit the data.

    Missing padding is not an error: padding carries no data, so this tool decodes the input anyway and notes that the padding was missing. Some libraries, such as Python's base64 module, do insist on it.

    Text or hex?

    The tool decides by checking, in order: a known file signature, NUL bytes, whether the bytes are valid UTF-8 (strictly, so no invalid sequence slips through), and how many control characters the text would contain. Valid UTF-8 alone is not enough: random bytes are sometimes valid UTF-8 but are still not text.

    This is a careful guess, so the result says why it chose one view, and the Text and Hex buttons let you switch. The hex view shows the first 64 KB as offsets, bytes and printable characters; Download always gives the full data.

    File types it recognises

    Types are recognised only from their first bytes, never from a name or a declared type. Anything else downloads as decoded.bin, so you never get a wrong extension.

    TypeDownloadPreview
    PNG imagedecoded.pngYes
    JPEG imagedecoded.jpgYes
    GIF imagedecoded.gifYes
    WebP imagedecoded.webpYes
    BMP imagedecoded.bmpNo
    ICO icondecoded.icoNo
    TIFF imagedecoded.tifNo
    PDF documentdecoded.pdfNo
    ZIP archivedecoded.zipNo
    gzip archivedecoded.gzNo
    7z archivedecoded.7zNo
    bzip2 archivedecoded.bz2No
    xz archivedecoded.xzNo
    WebAssembly moduledecoded.wasmNo
    SVG image (text starting with an <svg> element)decoded.svgYes, as a picture only

    Nothing leaves your browser

    Decoding runs on your device. Image previews are drawn from the decoded bytes, with no network request, and SVG files are shown as a picture only, so scripts inside them cannot run. Your input is never saved, uploaded or put in a link.

    Frequently asked questions

    Does it accept Base64 with line breaks or without padding?

    Yes. Line breaks, spaces, surrounding quotes and a data URL prefix are removed before decoding, and each removal is listed so nothing changes silently. Missing = padding and both the standard and URL-safe alphabets are accepted.

    How does it decide between text and hex?

    It checks the first bytes for a known file signature, then looks for NUL bytes, invalid UTF-8 and control characters. That is a well-tested guess, not a certainty, so you can switch between Text and Hex yourself.

    How is the file type of a download chosen?

    Only from the data's first bytes, its signature. A PNG starts with the same 8 bytes every time, for example. If no known signature matches, the download is a generic .bin file, never a guessed extension.

    Is the image preview safe?

    The image is shown from the decoded bytes on your device, with no network request. SVG images are shown only as a picture, so any script inside them cannot run.

    Decode Base64 in your code

    Each example decodes URL-safe Base64 without padding, decodes input with line breaks, and shows how its language reports invalid input. Note that some decoders skip invalid characters unless you ask them to check.

    Java

    import java.io.PrintStream;
    import java.nio.charset.StandardCharsets;
    import java.util.Base64;
    
    public class Base64Demo {
        public static void main(String[] args) {
            PrintStream out = new PrintStream(System.out, true, StandardCharsets.UTF_8);
            String text = "Hello, தமிழ் 👋!";
            byte[] data = text.getBytes(StandardCharsets.UTF_8);
    
            out.println(Base64.getEncoder().encodeToString(data));
    
            // URL-safe: - and _ instead of + and /, here without = padding.
            String urlSafe = Base64.getUrlEncoder().withoutPadding().encodeToString(data);
            out.println(urlSafe);
    
            // Java's decoders accept missing padding.
            out.println(new String(Base64.getUrlDecoder().decode(urlSafe), StandardCharsets.UTF_8));
    
            // The MIME decoder skips line breaks (and, careful, any other character
            // outside the alphabet). getMimeEncoder() writes 76-character lines with CRLF.
            out.println(new String(Base64.getMimeDecoder().decode("SGVsbG8s\nIHdvcmxk"), StandardCharsets.UTF_8));
    
            // The basic decoder rejects anything outside the alphabet.
            try {
                Base64.getDecoder().decode("SGVs!G8=");
            } catch (IllegalArgumentException e) {
                out.println("error: not valid Base64");
            }
        }
    }

    Standard library only (java.util.Base64, Java 8 or later; the PrintStream charset overload needs Java 10).

    JavaScript

    // Base64 in JavaScript (browsers and Node.js), standard library only.
    const text = 'Hello, தமிழ் 👋!';
    
    // btoa() only accepts Latin-1 characters, so turn the text into UTF-8 bytes first.
    const bytes = new TextEncoder().encode(text);
    let binary = '';
    for (const b of bytes) binary += String.fromCharCode(b);
    const b64 = btoa(binary);
    console.log(b64);
    
    // URL-safe: - and _ instead of + and /, usually without = padding.
    const urlSafe = b64.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
    console.log(urlSafe);
    
    // Decode: map back to the standard alphabet; atob() accepts missing padding.
    const fromBase64 = (s) => new TextDecoder().decode(Uint8Array.from(atob(s), (c) => c.charCodeAt(0)));
    console.log(fromBase64(urlSafe.replace(/-/g, '+').replace(/_/g, '/')));
    
    // atob() skips spaces and line breaks, so MIME and PEM bodies decode as they are.
    console.log(fromBase64('SGVsbG8s\nIHdvcmxk'));
    
    // Anything outside the alphabet throws.
    try {
      atob('SGVs!G8=');
    } catch {
      console.log('error: not valid Base64');
    }
    
    // Newer browsers also have Uint8Array.prototype.toBase64() and Uint8Array.fromBase64(),
    // with { alphabet: 'base64url', omitPadding: true } options. Check support first.

    Python

    # Base64 in Python, standard library only.
    import base64
    import binascii
    
    text = "Hello, தமிழ் 👋!"
    data = text.encode("utf-8")
    
    print(base64.b64encode(data).decode("ascii"))
    
    # URL-safe: - and _ instead of + and /. Strip the = padding if you do not want it.
    url_safe = base64.urlsafe_b64encode(data).decode("ascii").rstrip("=")
    print(url_safe)
    
    # urlsafe_b64decode needs the padding back.
    padded = url_safe + "=" * (-len(url_safe) % 4)
    print(base64.urlsafe_b64decode(padded).decode("utf-8"))
    
    # Without validate=True, b64decode drops every character outside the alphabet,
    # including line breaks (fine for MIME and PEM) but also real mistakes.
    print(base64.b64decode("SGVsbG8s\nIHdvcmxk").decode("utf-8"))
    
    # validate=True rejects anything outside the alphabet instead.
    try:
        base64.b64decode("SGVs!G8=", validate=True)
    except binascii.Error:
        print("error: not valid Base64")

    Go

    // Base64 in Go, standard library only.
    package main
    
    import (
    	"encoding/base64"
    	"fmt"
    )
    
    func main() {
    	text := "Hello, தமிழ் 👋!"
    	data := []byte(text) // Go strings are already UTF-8
    
    	fmt.Println(base64.StdEncoding.EncodeToString(data))
    
    	// RawURLEncoding: - and _ instead of + and /, no = padding.
    	urlSafe := base64.RawURLEncoding.EncodeToString(data)
    	fmt.Println(urlSafe)
    
    	decoded, err := base64.RawURLEncoding.DecodeString(urlSafe)
    	if err != nil {
    		panic(err)
    	}
    	fmt.Println(string(decoded))
    
    	// The decoders skip \r and \n, so MIME and PEM bodies decode as they are.
    	mime, err := base64.StdEncoding.DecodeString("SGVsbG8s\nIHdvcmxk")
    	if err != nil {
    		panic(err)
    	}
    	fmt.Println(string(mime))
    
    	// Anything else outside the alphabet is an error (a CorruptInputError with its offset).
    	if _, err := base64.StdEncoding.DecodeString("SGVs!G8="); err != nil {
    		fmt.Println("error: not valid Base64")
    	}
    }

    Last verified . Each example is run automatically and its output checked.

    Settings

    Deletes everything this site keeps in your browser: saved inputs, favorites, theme, accent color and tool options.