Home › Developer Tools › File to Base64

File to Base64

Drop any file to get its Base64 string, a ready-to-paste data URI, CSS, HTML or JSON. The file type is detected from its content, and the conversion happens on your device, so the file is never uploaded.

Last updated:

Drop files here or choose files
Any type: PDF, images, fonts, audio, ZIP, JSON… · or paste with Ctrl+V
No file yet Your file is read locally with the FileReader API. It is never uploaded.
Advertisement
Advertisement

How to use the File to Base64

  1. Add a file: drop it on the box, click to choose one or more files, or paste a copied file or screenshot.
  2. Check the MIME type detected from the file's content and change it if needed.
  3. Choose the output: plain Base64, data URI, CSS, HTML or JSON.
  4. Set line wrap or URL-safe if the target system expects it, for example 76 characters for email MIME or 64 for PEM.
  5. Copy or download the result. With several files, click a file in the list to show its output.

How Base64 encoding works

Base64 turns binary data into plain text using 64 safe characters: A–Z, a–z, 0–9, + and /. Every 3 bytes (24 bits) are split into four 6-bit groups, and each group becomes one character. If the file length is not a multiple of 3, the last group is padded with =.

Output length = 4 × ⌈bytes ÷ 3⌉ characters. A 1,000-byte file becomes 1,336 characters, about 33% larger. Line breaks add one or two more characters per line.

Common file signatures used for MIME detection

File typeFirst bytes (hex)Base64 starts withMIME type
PDF25 50 44 46 (%PDF)JVBERiapplication/pdf
PNG89 50 4E 47iVBORw0KGgoimage/png
JPEGFF D8 FF/9j/image/jpeg
GIF47 49 46 38 (GIF8)R0lGODimage/gif
ZIP, DOCX, XLSX50 4B 03 04 (PK)UEsDBapplication/zip, Office types
Gzip1F 8BH4sIapplication/gzip
WOFF2 font77 4F 46 32 (wOF2)d09GMgfont/woff2
MP3 with ID3 tag49 44 33 (ID3)SUQzaudio/mpeg

The "Base64 starts with" column is handy for recognising an unknown Base64 string: JVBERi is almost always a PDF and iVBORw0KGgo a PNG.

When to use a data URI, and when not to

  • Good fits: small icons, fonts or images in a single-file HTML page or email template, test fixtures, and JSON APIs that accept file contents as Base64.
  • Poor fits: large images and videos on websites. A data URI cannot be cached separately, is 33% larger and blocks the HTML or CSS that contains it.
  • Email: MIME attachments use Base64 with lines of at most 76 characters, which is what the 76-character wrap option produces.

Frequently asked questions

How do I convert a file to Base64?

Drop the file onto the box above or click it to choose a file. The Base64 string appears instantly. Click Copy result to put it on the clipboard or Download .txt to save it. The conversion uses your browser's FileReader, so the file never leaves your computer.

What is the difference between Base64 and a data URI?

Base64 is just the encoded bytes, for example JVBERi0xLjQK... for a PDF. A data URI adds a prefix with the MIME type, data:application/pdf;base64,JVBERi0xLjQK..., so a browser can use it directly in an href, src or CSS url(). APIs and JSON payloads usually want plain Base64.

Why is the Base64 output bigger than the file?

Base64 represents every 3 bytes with 4 ASCII characters, so the output is about 33% larger than the original (plus padding, and line breaks if you wrap). A 300 KB file becomes about 400 KB of text. That is why large files are better linked than embedded.

How is the MIME type detected?

The tool reads the first bytes of the file and matches known signatures, such as 89 50 4E 47 for PNG, 25 50 44 46 (%PDF) for PDF and 50 4B 03 04 for ZIP-based files. If the signature is unknown it falls back to the type reported by your system and the file extension. You can always type a different MIME type.

When should I wrap Base64 lines?

Email (MIME, RFC 2045) limits encoded lines to 76 characters and PEM files for certificates and keys use 64. JSON, data URIs, HTML and most APIs expect one unbroken line, so leave wrapping off unless the target requires it.

What is URL-safe Base64?

Base64url (RFC 4648 section 5) replaces + with - and / with _ and usually drops the = padding so the string can be used in URLs and file names without escaping. It is used by JWT tokens and many web APIs. Data URIs always use standard Base64.

Is there a file size limit?

There is no upload, so the limit is your device's memory. Files of tens of megabytes convert in a second or two. For very large files the output box shows only the beginning to keep the page responsive, while Copy and Download still use the full string.

Are all the tools on FreeToolCabin tested for quality and accuracy?

Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.

Related tools

Base64 Encoder DecoderEncode or decode Base64 text and files, and make data URIs.Image to Base64Convert images to Base64 data URIs, CSS backgrounds and HTML img tags in your browser.Base64 to PDFDecode a Base64 string to a PDF with preview and download, or encode a PDF to Base64.MIME Type LookupFind the MIME type for any file extension, or the extensions for a MIME type, in 400+ entries.File Encryption ToolEncrypt and decrypt any file with a password using AES-256-GCM, entirely in your browser.Initials Avatar GeneratorCreate letter avatars from names: shapes, colors, fonts, bulk ZIP, PNG/SVG and data URIs.PDF ConverterConvert Word, Excel, PowerPoint, images, text, HTML or EPUB to PDF, and PDF to JPG, PNG, Word or text.Protobuf DecoderDecode raw Protocol Buffers hex or Base64 without a schema, or add a .proto for field names.JSON to Excel ConverterTurn JSON into a styled .xlsx spreadsheet; nested arrays become their own linked sheets.JSON to CSVConvert JSON data to CSV for spreadsheets.CSV to JSONConvert CSV data to JSON with live preview.Excel to CSVConvert XLSX spreadsheets to CSV.CSV ViewerOpen a CSV or TSV file as a sortable, filterable table.Excel Viewer (XLSX / XLS)Open XLSX, XLS and ODS spreadsheets in your browser without Excel.Line Ending ConverterConvert text and files between CRLF, LF and CR line endings.Markdown to HTMLConvert Markdown to clean HTML with a live editor.XML to JSONConvert XML to JSON with validation.Text Encoding ConverterDetect and convert text file encodings like UTF-8, UTF-16 and Latin-1.JSON ViewerExplore JSON as a collapsible tree, search keys and values and copy any node's path.TTF to WOFF2 ConverterConvert TTF and OTF fonts to WOFF2 or WOFF and get a ready @font-face CSS snippet.Chmod CalculatorConvert Linux file permissions between checkboxes, octal (755) and symbolic (rwxr-xr-x) notation.JSON to TypeScriptGenerate TypeScript interfaces or types from JSON, with nested types and optional fields.Morse Code TranslatorTranslate text to Morse code and back, then play it as sound or a blinking light, or save a WAV.HTML Table GeneratorBuild HTML tables in an editable grid with styles, header rows, CSV import and live preview.Hex to Text ConverterConvert hex to text and text to hex with UTF-8 support and space, 0x, \x or comma formats.JSON to XML ConverterConvert JSON to well-formed XML with attributes, arrays and pretty print.JSON to YAML ConverterConvert JSON to clean YAML as you type, with indent, quoting and sort options.YAML to JSON ConverterConvert YAML to pretty or minified JSON, with errors pinned to the exact line.HTML to Markdown ConverterTurn HTML or pasted rich text into clean Markdown with tables and live preview.Markdown Table GeneratorBuild Markdown tables in a grid or paste from Excel/CSV, with alignment and preview.JSON ValidatorCheck JSON with the exact line and column of each error, fix tips and one-click auto-fix.Base64 to ImagePaste a Base64 string or data URI to preview, identify and download the image.JSON CompareCompare two JSON documents and see every added, removed and changed path.Hex to DecimalConvert hex to decimal instantly with steps and signed mode.Decimal to HexConvert decimal to hex instantly with steps and signed mode.Binary to DecimalConvert binary to decimal instantly with steps and signed mode.Decimal to BinaryConvert decimal to binary instantly with steps and signed mode.Two's Complement CalculatorDecimal to two's complement binary and back for 4-64 bits, with invert-and-add-1 steps.CSV to SQL ConverterConvert CSV to SQL CREATE TABLE and INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server.IPv4 to IPv6 ConverterConvert IPv4 to IPv4-mapped, 6to4 and NAT64 IPv6, extract IPv4 from IPv6, and get int/hex/binary.cURL to Code ConverterConvert curl commands to JavaScript fetch, Axios, Python requests, Node.js, PHP and Go code.Code to ImageTurn code into a beautiful syntax-highlighted PNG with themes, window frame and background.Excel to JSON ConverterConvert Excel sheets (XLSX, XLS, ODS) to JSON with header row, type and shape options.CSV to Excel ConverterConvert CSV files to a real .xlsx workbook with typed numbers and dates, one sheet per file.CSV SplitterSplit a large CSV into smaller files by row count, file count or column value, header kept.CSV MergerCombine many CSV files into one, matching columns by name, with dedupe and a source column.VCF to CSV ConverterConvert vCard (.vcf) contacts to CSV for Google or Outlook, or turn a CSV back into a VCF.Calendar Event (.ics) GeneratorCreate an .ics calendar invite with time zone, reminders and repeats + Google/Outlook links.CSV Column ExtractorPick, reorder and rename CSV columns, filter rows by value, and export a new CSV or JSON.CSV Diff CheckerCompare two CSV files by key column and see added, removed and changed rows cell by cell.CSV Duplicate Row RemoverRemove duplicate rows from a CSV by all or selected columns and download the cleaned file.CSV to HTML TableTurn CSV into clean HTML table code with a live preview, styling options and one-click copy.CSV to Markdown TableConvert CSV to a neatly aligned GitHub Markdown table with column alignment and live preview.CSV TransposeSwap rows and columns of CSV, TSV or pasted spreadsheet data, with delimiter auto-detect.Date Format ConverterConvert any date to ISO 8601, RFC 2822, Unix time and custom strftime, moment or Java patterns.ENV to JSON ConverterConvert .env files to JSON or YAML and JSON back to .env, with quotes and multiline values.HTML Table to CSVExtract any table from HTML or page source to CSV, TSV or JSON, with colspan and rowspan handled.IEEE 754 Floating Point ConverterConvert decimals to 32/64-bit IEEE 754 floats: toggle bits, see hex, exact value and rounding error.INI to JSON ConverterConvert INI and CFG files to JSON and JSON back to INI, with sections, arrays and types.IP Address ConverterConvert IPv4 to decimal, hex, binary, octal and back, with class and private/public check.ISBN Converter & ValidatorConvert ISBN-10 to ISBN-13 and back, validate check digits and hyphenate, one or in bulk.JSON Flatten / UnflattenFlatten nested JSON to dot or bracket path keys, or unflatten flat keys back to nested JSON.JSON to Dart ClassTurn JSON into Dart model classes with fromJson, toJson, null safety and nested classes.JSON to Java ClassTurn JSON into Java POJOs or records with Lombok, getters/setters and Jackson or Gson annotations.JSON to Kotlin Data ClassTurn JSON into Kotlin data classes for kotlinx.serialization, Gson, Moshi or Jackson.JSON to Markdown TableTurn a JSON array of objects into a GitHub Markdown table with column picker and alignment.JSON to PHP ArrayConvert JSON to PHP array code (short [] or array()) and PHP arrays back to JSON.JSON to Rust StructTurn JSON into Rust structs with serde derives, rename attributes, Option and Vec types.
See all 129 Data & File Format Converters →