Upload a file
  1. base64hub
  2. File tools
  3. Base64 to file

Base64 to File Converter

Paste a Base64 string of unknown origin and the tool works out what the file is from its first bytes, shows it and saves it with the correct extension. Everything runs in this browser tab.

Free no sign-up, no limits Local nothing uploaded Auto detects 60+ file types Updated Oct 27, 2026
Input –Output –Size –

Processed in your browser. This page cannot send your data anywhere – how we know

How to decode Base64 to a file

  1. Paste the string into Base64 or data URI. Standard and URL-safe Base64 are both accepted, with or without padding, line breaks or quotes. A whole data URI works, and so does text that contains one: a CSS url("data:…"), an HTML src="data:…" or a Markdown image. For a long string in a file, use Open .txt file or drop it on the box.
  2. Read the status line under the input: whether the input is valid, which variant it is (Standard or Base64URL), the decoded size and the Detected type. A data URI also shows its Declared type.
  3. Look at the preview and the three fields below it. File name, Extension and MIME type are filled in from the detection. Anything you type there stays until you press Clear.
  4. Press Download file, or Copy as data URI to get the bytes back as data:<MIME type>;base64,….

Sample loads a different test file on each click: PNG, PDF, ZIP, WAV, DOCX, JSON, gzip and SVG. If you drop a file that is already binary, say a PDF instead of a text file holding its Base64, the tool tells you so and links to File to Base64, which goes the other way.

Why the file shows up as application/octet-stream

application/octet-stream means “some bytes, type unknown”. It ends up in front of Base64 for ordinary reasons. Chrome’s FileReader.readAsDataURL() produces data:application/octet-stream;base64, for any file whose type the browser does not know. Storage and export systems that keep the bytes but not the type label everything that way. Some APIs declare every attachment as octet-stream. A viewer that relies on the label then refuses to show the file, and a download gets no useful extension.

The bytes themselves usually identify the format: most formats begin with a fixed signature, and the tool checks more than 60 of them. A few signatures are shared, so the tool looks further into the file:

First bytesBase64 starts withCould beHow the tool tells them apart
PK 03 04UEsDBZIP, DOCX, XLSX, PPTX, EPUB, ODT, ODS, JAR, APKEntry names: word/, xl/, ppt/, the mimetype entry, AndroidManifest.xml, META-INF/MANIFEST.MF
RIFFUklGRWebP, WAV, AVIThe four letters at byte 8
ftyp at byte 4AAAA, for example AAAAIGZ0eXBMP4, M4A, MOV, 3GP, HEIC, AVIFThe brand at bytes 8 to 11
OggST2dnUwOgg Vorbis, Opus, Theora videoThe codec header in the first page
1A 45 DF A3GkXfoWebM, MKVThe webm document type
D0 CF 11 E00M8R4KGxGuEDOC, XLS, PPT, Outlook MSG, password-protected Office filesIt cannot; it reports “DOC/XLS/MSG (OLE)”

The full list of signatures is on common Base64 prefixes.

When a data URI declares a type and the content disagrees, a note says so, for example “The data URI says application/octet-stream, but the content looks like PDF.”, and the detected type is used. The declared type wins only when detection is weak: when the bytes look like plain text or unknown binary.

Base64 inside Base64, URL encoding and gzip

Data that went through several systems is often wrapped more than once. After decoding, the tool checks whether the result is another layer and offers Decode again:

NoteWhat happened
“The decoded data is itself Base64 text (inside: PDF).”Encoded twice, typically by two layers of code that each encoded “to be safe”
“The decoded data is URL-encoded Base64”The Base64 was percent-encoded for a URL (%2B, %2F, %3D) before being encoded again
“The decoded data is a data: URI.”Someone encoded the whole data:… string instead of its payload
“The data is gzip-compressed: 817 B unpacked (PDF).”Compressed before encoding to save space, common in logs and message queues; zlib is recognized too

Decode again puts the inner layer into the input and decodes it; Back steps out again and remembers up to 20 steps. The gzip and zlib notes appear only after the tool has actually unpacked the data, for results up to 16 MB. The gzip preview also shows the original file name and modification time stored in the header, with Save unpacked for the content. For text payloads, the gzip Base64 decoder is the more direct tool.

Saving with the right extension

Windows and macOS pick the program by extension, so a PDF saved as decoded.bin looks broken even though every byte is right. The Extension and MIME type fields follow the detection until you type in them:

  • The file name comes from a name= or filename= parameter in a data URI, or from the name of the text file you opened, without its .txt or .b64 ending: report.pdf.b64.txt is saved as report.pdf.
  • For an OLE file you know is a spreadsheet, type xls in Extension; the tool cannot tell DOC, XLS and MSG apart.
  • A MIME type you enter also re-renders the preview as that kind. If the tool says Binary but you expect audio, typing audio/ogg makes it try the audio player.
  • The MIME type affects only the download and Copy as data URI; a file on disk has no MIME type, only its bytes and its name.

What the preview shows

Every result lists type, MIME type, extension, size and a SHA-256 hash, with Show hex dump for the first 512 bytes. The hex dump is open from the start for unknown binary data. Depending on the kind:

KindPreview
ImagesThe picture and its pixel size; HEIC, TIFF and JPEG XL usually get a “can’t display” note because most browsers lack a decoder. See Base64 to image.
PDFYour browser’s PDF viewer, version, page count, title. See Base64 to PDF.
Audio and videoA player with duration and video size
FontsEditable sample text in the decoded font, with family, style and glyph count
ZIP, DOCX, XLSX, PPTX, EPUBThe entry list with View and Save for each file, plus document text for Office files and e-books. See Base64 to ZIP.
TextCharset, lines, pretty-printed JSON, a table for CSV, the root element for XML, sandboxed HTML
Certificates and keysA link to the certificate decoder

Detect the MIME type of Base64 in code

Twenty-four characters of Base64 decode to 18 bytes, enough for the common signatures. This works in browsers and in Node.js 16 and later:

function sniffMime(b64) {
  const head = b64.replace(/^data:[^,]*,/, "").replace(/\s+/g, "").slice(0, 24)
    .replace(/-/g, "+").replace(/_/g, "/");
  const b = Uint8Array.from(atob(head), (c) => c.charCodeAt(0));
  const str = (start, len) => String.fromCharCode(...b.subarray(start, start + len));

  if (str(0, 5) === "%PDF-") return "application/pdf";
  if (str(0, 8) === "\x89PNG\r\n\x1a\n") return "image/png";
  if (b[0] === 0xff && b[1] === 0xd8 && b[2] === 0xff) return "image/jpeg";
  if (str(0, 4) === "GIF8") return "image/gif";
  if (str(0, 4) === "RIFF" && str(8, 4) === "WEBP") return "image/webp";
  if (str(0, 4) === "RIFF" && str(8, 4) === "WAVE") return "audio/wav";
  if (str(4, 4) === "ftyp") return "video/mp4"; // also M4A, MOV, HEIC: see bytes 8-11
  if (str(0, 4) === "PK\x03\x04") return "application/zip"; // also DOCX, XLSX, PPTX
  if (b[0] === 0x1f && b[1] === 0x8b) return "application/gzip";
  if (str(0, 3) === "ID3" || (b[0] === 0xff && (b[1] & 0xe6) === 0xe2)) return "audio/mpeg";
  return "application/octet-stream";
}

sniffMime("data:application/octet-stream;base64,JVBERi0xLjcKJeLjz9MK"); // "application/pdf"

On the command line, file reads the decoded bytes from standard input:

base64 -d payload.b64 | file -b --mime-type -

That prints application/pdf for a PDF. If you decode with OpenSSL instead, add -A for a string on a single line. Without it, openssl base64 -d silently writes nothing when the line has no final newline or is too long (1,024 characters or more in OpenSSL 3.5). More on Base64 in JavaScript and Base64 in Bash.

FAQ

How do I get the MIME type of a Base64 string?

Decode the first few bytes and compare them with known file signatures: JVBERi0 decodes to %PDF-, iVBORw0KGgo to the PNG signature. This page does that for more than 60 formats, and the JavaScript function on this page covers the common ones in your own code.

What does "cannot display the file as application/octet-stream" mean?

application/octet-stream is the generic label for bytes of unknown type, so a viewer that trusts the label has nothing to go on. Paste the same string here: the content is examined instead of the label, and the extension and MIME type are filled in for you.

What can I do when the type is not detected?

The preview then shows Binary with a hex dump of the first 512 bytes. If you know the format, type the extension and MIME type before downloading; the MIME type also switches the preview, so audio/ogg makes the tool try to play the bytes.

How large a file can I decode?

There is no fixed limit; the memory of your device is the bound. Above roughly 50 MB of Base64 the page pauses for a moment while it decodes, and Copy as data URI is turned off for files over 32 MB.

Does the file get uploaded anywhere?

No. Decoding, type detection and preview run in your browser, and the page’s Content Security Policy stops the page from sending network requests, except Cloudflare’s page-view count.