Home › Developer Tools › Image to Base64

Image to Base64

Drop, paste or choose an image to get its Base64 code instantly: a ready-to-use data URI, raw Base64, a CSS background rule or an HTML img tag. Your images never leave your device.

Last updated:

Drop images here or choose files
PNG, JPG, WebP, GIF, SVG, AVIF, ICO, BMP · or paste with Ctrl+V
Preview of the selected image
Sample image
Type
-
Dimensions
-
File size
-
Base64 size
-
0 characters
Advertisement
Advertisement

How to use the Image to Base64

  1. Add an image: drag it onto the drop area, click to choose a file, or paste a screenshot with Ctrl+V. You can add several at once.
  2. Pick a format from the tabs: Data URI, Base64 only, CSS, HTML <img>, Markdown or JSON.
  3. Optionally shrink it: choose Re-encode as WebP or JPEG and set a max width to get a much shorter string.
  4. Copy or download the code and paste it into your HTML, CSS, JSON or email template.
  5. Switch images with the thumbnails if you added more than one.

How Base64 image encoding works

Base64 reads the file 3 bytes (24 bits) at a time and splits them into four 6-bit groups. Each group is a number from 0 to 63 that maps to one character of the alphabet A–Z a–z 0–9 + /. If the file length is not a multiple of 3, the last group is padded with one or two = signs. That is why the encoded size is always 4 × ⌈bytes ÷ 3⌉ characters, about 33% more than the original file.

A data URI wraps that text with the file type so browsers know how to decode it: data:[MIME type];base64,[data]. For example a PNG starts with data:image/png;base64,iVBORw0KGgo, because every PNG file begins with the same 8 signature bytes.

Where to use each output

OutputUse it forExample
Data URIAny place that accepts a URL: img src, CSS url(), JavaScript, canvasdata:image/png;base64,iVBOR…
Base64APIs and JSON fields that expect only the encoded bytes, email MIME partsiVBORw0KGgoAAAANSUhEUg…
CSSSmall icons and background patterns inside a stylesheetbackground-image: url("data:…")
HTML <img>Single-file HTML pages, email templates, offline docs<img src="data:…" alt="logo">
MarkdownREADME files and notes that must embed the picture![logo](data:…)
JSONSending an image with its name, type and size to an API{"mime": "image/png", "base64": "…"}

Tips for shorter Base64 strings

  • Inline only small files. Icons under about 5 to 10 KB are good candidates. Larger images are better served as normal files that the browser can cache.
  • Re-encode photos as WebP or JPEG and set a max width close to the size you actually display. A 4000 px phone photo shown at 400 px can shrink by more than 95%.
  • Keep PNG for flat graphics with sharp edges or transparency. JPEG has no transparency, so transparent areas are filled with white.
  • SVG icons are often smallest as SVG. Minify the SVG first, then encode it.
  • Email: many email clients, including Gmail, block data URI images. For email, attach the image or host it instead.

Frequently asked questions

What is a Base64 image?

It is the image file's bytes written as text using 64 safe characters (A-Z, a-z, 0-9, + and /). Put inside a data URI such as data:image/png;base64,..., it can be used directly in an img src, a CSS url() or JSON without a separate file.

Why is the Base64 string bigger than the image?

Base64 turns every 3 bytes into 4 characters, so the text is about 33% larger than the original file (plus a few characters of padding and the data URI prefix). Gzip or Brotli compression on your server wins some of that back.

When should I inline images as Base64?

It is useful for small icons, logos and placeholders (a few KB), for single-file HTML pages, email templates and JSON APIs. For large photos a normal image file is better because it can be cached separately and does not bloat your HTML or CSS.

Are my images uploaded to a server?

No. The file is read with the browser's FileReader API and encoded on your device. Nothing is sent anywhere, so it is safe for private screenshots and unreleased designs.

Can I convert SVG to Base64?

Yes. SVG files are encoded exactly like other images and get the image/svg+xml MIME type. For SVG you can also use a URL-encoded data URI, but Base64 works everywhere and avoids escaping problems.

How do I turn Base64 back into an image?

Use the Base64 to Image tool: paste the data URI or raw Base64 and it shows a preview, detects the file type and lets you download the image.

Is there a size limit?

There is no fixed limit, but very large strings (tens of MB) can make the page slow. For big photos, use the re-encode option to resize and compress first.

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 to ImagePaste a Base64 string or data URI to preview, identify and download the image.Base64 Encoder DecoderEncode or decode Base64 text and files, and make data URIs.Image CompressorShrink images to a target size like 100 KB.SVG to PNGConvert SVG graphics to PNG or JPEG at any scale.CSS Sprite GeneratorPack many icons into one sprite sheet PNG and get CSS classes with background-position.HTML Image Map GeneratorDraw clickable rectangle, circle and polygon hotspots on an image and get image map HTML.ICO to PNGExtract every size from ICO and CUR icon files and save them as PNG images or a ZIP.Paste Image to FilePaste a clipboard image with Ctrl+V and save it as PNG, JPG or WebP, or copy images to the clipboard.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.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.XML to CSV ConverterConvert XML to CSV: detects repeating records, flattens nested data, pick your columns.Wildcard Mask CalculatorConvert a subnet mask or CIDR to a wildcard mask for ACLs and OSPF, with range and binary.CSV to VCF ConverterConvert a contacts CSV into a vCard (.vcf) file, mapping columns to name, phone, email and more.CSV to YAML ConverterConvert CSV rows to a YAML list of mappings with type inference and delimiter detection.Endianness ConverterSwap byte order of 16, 32 and 64-bit hex values and see big- and little-endian integers and floats.Excel to SQL ConverterTurn an Excel sheet into CREATE TABLE and INSERT statements for MySQL, PostgreSQL, SQLite or SQL Server.Excel to VCF ConverterTurn an Excel contact list into a vCard .vcf file for iPhone, Android, Google or Outlook.File to C ArrayConvert any file into a C or C++ byte array header, like xxd -i, with const and PROGMEM options.Image to C ArrayConvert images to monochrome, RGB565 or RGB888 C arrays for OLED, LCD and TFT displays.JSON Merge ToolDeep-merge two or more JSON objects with array concat, replace or union and a conflict rule.JSONL to CSV ConverterConvert JSON Lines / NDJSON to CSV with flattened columns; streams large files locally.PHP Unserialize OnlineDecode PHP serialize() strings to JSON, a tree or print_r, and serialize JSON back to PHP.SQL Dialect ConverterTranslate SQL between MySQL, PostgreSQL, SQLite, SQL Server, Oracle, BigQuery and more.TSV to JSON ConverterTurn tab-separated data pasted from Excel or Sheets into a JSON array or keyed object.XLS to XLSX ConverterConvert old Excel 97-2003 .xls workbooks to modern .xlsx files in your browser, several at once.XML to Excel ConverterTurn repeating XML elements into an .xlsx spreadsheet with attributes and nested data as columns.XSD to XML Sample GeneratorGenerate a sample XML document from an XSD schema, with types, attributes and namespaces.YAML to CSV ConverterTurn a YAML list of objects into CSV with dot-notation columns, custom column order and download.DOCX to Markdown ConverterConvert Word .docx to clean Markdown with headings, lists, tables, links and images in a ZIP.ES6 to ES5 ConverterTranspile modern JavaScript (ES2015+) to ES5 with Babel: targets, module format and loose mode.JavaScript Object to JSONTurn JS object literals and Python dicts into valid JSON: quotes keys, fixes commas and values.JSON Graph VisualizerSee JSON as an interactive node graph with zoom, collapse and search; export PNG or SVG.KML ViewerOpen KML and KMZ files on an interactive map: placemarks, paths, polygons, folders, export.MySQL to PostgreSQL ConverterConvert MySQL dumps and CREATE TABLE statements to PostgreSQL: types, AUTO_INCREMENT, ENUMs, quotes.Text to CSV ConverterTurn space-aligned, fixed-width, pipe or tab separated text into clean CSV with a live preview.VCF File ViewerOpen vCard .vcf files as contact cards with photos, search and duplicate check, export CSV.XML ViewerBrowse XML as a collapsible tree with search, XPath of any node, attributes and big-file support.CSV to XML ConverterConvert CSV to well-formed XML with custom root and row names, escaping and pretty print.TOML to JSON ConverterConvert TOML to JSON and JSON to TOML with a full v1.0 parser and clear error lines.JSON to Go StructTurn JSON into Go structs with inferred types, nested structs and json tags.JSON to Python ClassGenerate Python dataclasses, Pydantic models or TypedDicts with type hints from JSON.
See all 129 Data & File Format Converters →