{{ summaryTitle }}

{{ summaryValue }}
{{ summaryLine }}
{{ outputMimeLabel }} {{ outputDimensionsLabel }} {{ focusStatusLabel }}
Image source and inline encoding settings
Drop, paste, browse, or restore the generated SVG sample. Extra files are ignored.
{{ sourceDropTitle }} {{ sourceDropLine }}

{{ sourceStatus }}

{{ statusAnnouncement }}
Raw Base64 or data:image/…;base64,…. Up to 64 MiB restored bytes and 96 MiB text. Percent-encoded Data URIs and HTML/CSS snippets are not supported.

{{ decodeError || (decodeState === 'loading' ? 'Restoring image bytes locally…' : hasDecodedResult ? decodedNotice : 'The pasted payload stays in this browser tab and is excluded from the URL.') }}

Encode an image as text or restore an image from Base64. Each source remains in this tab while you switch.
Keep off for byte-exact output; enable only when a rendered payload is acceptable.
{{ optimize ? 'On' : 'Off' }}
Used only while optimization is on.
{{ quality }}%
Lower values usually shorten photographic payloads at the cost of detail.
Use 0 for original dimensions or a value from 16 to 12,000 pixels.
px
Used only for optimized JPEG output.
Choose no wrapping, 64 columns, or MIME-style 76 columns.
Leave blank unless a downstream consumer explicitly requires another image media label.
{{ decodeAnnouncement }}
Detected format
{{ decodedInfo.mime }}
Declared type
{{ decodedInfo.declaredMime || 'None (raw Base64)' }}
Restored size
{{ formatNumber(decodedBytes.length) }} bytes
Header dimensions
{{ decodedInfo.width && decodedInfo.height ? `${decodedInfo.width} × ${decodedInfo.height} px` : 'Unavailable' }}
Restored image preview

{{ decodedInfo.previewReason }}

{{ decodedNotice }} Preview uses an image element; it does not sanitize the downloaded file. SVG scripts and external resources stay inactive here, but the original SVG may behave differently when opened as a document.

{{ payloadExportAnnouncement }}
{{ visiblePayloadText }}
{{ imageDownloadAnnouncement }}
{{ tableExportAnnouncement }}
TargetCharactersPreviewCopy
{{ row.label }}{{ formatNumber(row.characters) }}{{ row.preview }}
{{ tableExportAnnouncement }}
ContextFitBandsGuidanceCopy
{{ row.label }}{{ statusLabel(row.status) }}{{ formatNumber(row.soft) }} / {{ formatNumber(row.caution) }} chars{{ row.guidance }}
{{ chartExportAnnouncement }}
{{ chartError || 'Preparing payload expansion chart…' }}

For the current {{ formatNumber(outputInfo.size) }}-byte image, this comparison spans hypothetical inputs from 0 to {{ formatNumber(outputInfo.size * 2) }} bytes using the {{ payloadMime }} prefix. Dots mark the current image. Other points show content-independent lengths, not newly encoded images; ASCII text uses one byte per character.

Similar tools

An image can be carried inside a text field without changing its file format. Base64 represents the file's bytes using printable characters, allowing an image to travel in a JSON message, a document, or another format that expects text. Decoding that text recovers the bytes it represents. A JPEG remains a JPEG throughout this round trip unless a separate image conversion takes place.

Raw Base64 supplies the encoded content without saying what kind of file it contains. A Data URI, also called a data URL, adds that information and makes the content usable as an inline resource. The prefix data:image/png;base64, declares PNG data and marks the text after the comma as Base64. Here, the MIME type is a media label describing the intended format. Changing that label alone cannot turn PNG bytes into JPEG bytes.

The receiving field must expect the same representation. An HTML image source or CSS image URL can use a complete Data URI when the destination permits it. An API may instead require only the raw Base64 text. Standard Base64 uses letters, digits, +, and /; Base64URL substitutes - and _ for those last two symbols. A Data URI does not require the Base64URL alphabet merely because it is a URL.

Three input bytes normally become four Base64 characters. A final incomplete group uses one or two = padding characters, so short inputs can grow by much more than one third. The Data URI prefix adds further text. Base64 is therefore neither compression nor encryption. It does not remove image detail to save space, and anyone who receives the text can decode it without a secret key.

A lossless text round trip preserves everything in the encoded file, including its existing metadata and animation data. Resizing or re-encoding an image is a separate operation that creates new bytes. Even a lossless PNG export preserves the rendered pixels rather than guaranteeing the original file, metadata, color information, or animation survives unchanged. JPEG and other lossy exports can also alter visible detail.

The choice between embedding an image and linking to a separate file depends on how it will be delivered and reused.

  • Embedding can keep a small illustration with a self-contained document and avoid a separate request for that image. Its encoded text enlarges the containing document, and repeating the full string repeats that content.
  • A separate image URL allows the image to be cached and updated independently of the document. This is often more practical for large photographs or images reused across several pages.

Neither choice guarantees faster delivery. File size, reuse, caching, and the receiving application's support all matter. Email software can treat embedded images differently from a browser, and an API can impose its own request-size rules. Embedded image text also carries the image into any document, message, or log that records it, so sharing the encoded string deserves the same care as sharing the file.

How to Use This Tool:

Choose the conversion direction first. Results update when the source or relevant settings change; there is no separate conversion button.

Encode an image

  1. Choose Image → Base64, then browse, drop, or paste an image. The encoder initially contains a generated SVG demonstration. The first recognized image is used when several files arrive, and extra files are ignored. Supply a nonempty, browser-readable image no larger than 5 MiB, with neither dimension above 12,000 pixels.
  2. Leave Optimize before encoding off to retain the received file bytes. Browse or drop the file when exact identity to a file on disk matters, because clipboard software may supply a different image encoding. For a rendered image, open Advanced, enable optimization, and choose PNG, JPEG, or WebP. The initial rendering settings are WebP at 88% quality with the original dimensions.
  3. Set Maximum long edge if you want a smaller rendered image. Zero keeps the dimensions; positive values use 16 to 12,000 pixels and never enlarge the image. Lossy quality ranges from 10% to 100% for JPEG and WebP; PNG ignores it. For JPEG, choose a background color to replace transparent areas, initially white.
  4. Choose the Payload view expected by the destination: raw Base64, Data URI, HTML image, or CSS background. For HTML, replace the sample Alt text with a useful text alternative, leaving it empty only for a decorative image. Raw Base64 can optionally wrap at 64 or 76 columns.
  5. Review the image and the destination selected under Recommendation lens, then use Copy text or Download TXT for the complete selected representation. Download image saves the image bytes being encoded, including any enabled rendering changes.
    Leave Data URI MIME label blank unless a receiving system requires an override. A valid override only relabels the text representation. An invalid label is ignored with a warning.

Restore an image from text

  1. Choose Base64 → image and paste raw standard Base64 or a complete image Base64 Data URI into Image Base64. Use sample supplies a generated SVG example for this direction.
    Paste the encoded value itself, without HTML, CSS, or surrounding JSON quotation marks. If padding or alphabet errors appear, copy the complete original value again. Clear returns to an empty input, and Use sample provides a known working value.
  2. Check Detected format, Declared type, and Restored size. A mismatch is reported without converting the bytes. A preview may be unavailable even when the image can be downloaded.
  3. Select Download image to save the restored bytes. The file type follows the detected image format; restoration does not re-render the image or recover its original filename.

Interpreting Results:

The encoder's headline counts the unwrapped Base64 characters. The summary also gives the complete Data URI length and the Base64 overhead relative to the image bytes currently being encoded. When optimization is on, these figures describe the rendered image, not the original file. The payload display stops after 16,000 characters for long results; copying or downloading retains the full value.

Fits well, Review size, and External file preferred are size recommendations. They do not test an email client, validate an API request, or establish a browser's maximum URL length. Choose your actual destination and test the copied value there. A favorable size label cannot make an unsupported image format or embedding method work.

For restoration, valid Base64 proves that text can be converted to bytes. Detected format means those bytes have a recognized image header. A successful preview adds evidence that the browser can display the image, but none of these checks establishes complete file validity or safety. Unknown image headers are rejected; recognized images can remain downloadable when their contents are unsupported, damaged, or outside the preview limits.

Embed snippets contains HTML, CSS, and a JSON-quoted Data URI string. Its table and Delivery fit retain complete values in copied rows and CSV or DOCX exports even when a visible snippet is shortened. Row copying transfers table data; use the payload's Copy text for the bare selected representation. Payload expansion exports the size comparison as a chart image or CSV.

Technical Details:

Base64 transforms file bytes, regardless of whether they describe pixels, metadata, or vector shapes. Equal byte counts produce equal Base64 lengths even when the pictures look completely different. Image complexity matters only if an image encoder first creates a different file.

Transformation Core

Each group of three bytes supplies 24 bits, which are split into four six-bit values. Values 0 to 25 map to uppercase letters, 26 to 51 to lowercase letters, 52 to 61 to digits, and 62 and 63 to + and /. For example, the first three bytes of a PNG signature follow this path.

Encoding the first three PNG signature bytes as four Base64 characters
RepresentationValue
Three hexadecimal bytes89 50 4E
Four six-bit groups100010 010101 000001 001110
Alphabet positions34 21 1 14
Base64 textiVBO

This is only a signature fragment, not a complete image. Decoding reverses the grouping to recover the same three bytes. A final single byte uses two alphabet characters and ==; two final bytes use three alphabet characters and =. The unused bits in the final alphabet character must be zero for a canonical encoding.

Formula Core

The padded text length rounds the binary byte count up to complete three-byte groups. Adding the exact Data URI prefix gives the complete inline length; the overhead percentage below measures raw Base64 expansion only.

C=4×⌈B3⌉ D=C+P H=100×C−BB

B is the encoded image's byte count, C is its padded Base64 character count, P is the prefix length, D is the complete Data URI character count, and H is overhead in percent for a nonempty image. The ceiling brackets mean round upward to an integer. Prefix lengths include the comma: PNG uses 22 characters, JPEG and WebP use 23, and SVG uses 26.

Short byte sequences show why the increase is not always exactly one third. These are length examples using a PNG prefix, not usable image files.

Exact Base64 and PNG Data URI lengths for zero through three binary bytes
Binary bytesBase64 charactersData URI charactersRaw overhead
0022Undefined
1426300%
2426100%
342633⅓%

Zero bytes appear only in the hypothetical size comparison; an actual image must be nonempty. Base64 and the generated prefixes use ASCII, a basic character set whose characters each occupy one byte in UTF-8 text. Their character counts therefore equal their uncompressed text byte counts. These figures do not measure compressed network traffic or browser memory use. Summary overhead is displayed to one decimal place, while lengths and exported table values retain exact integers. KiB means 1,024 bytes and MiB means 1,048,576 bytes; rounded size labels do not alter the underlying counts.

Wrapping, labels, and enclosing text

Raw wrapping adds one line-feed character between rows and no final newline. For a nonempty Base64 string of C characters and a width w of 64 or 76, the wrapped length L includes those separators.

L=C+⌈Cw⌉−1

Data URIs and HTML, CSS, and JSON snippets remain unwrapped. The summary and delivery bands exclude raw line breaks. A MIME override changes P and possibly D, but leaves B and C unchanged. Image previews and image downloads use the actual output type rather than the overridden text label.

HTML adds an image element and an escaped alt attribute. Ampersands, double quotation marks, and angle brackets in alt text are escaped so they remain attribute content. CSS adds its surrounding rule, and JSON adds string quotation and escaping. Those enclosing characters are counted in their snippet rows, but are not part of the image or the Data URI size recommendation. Non-ASCII alt text can make a snippet's text-length count differ from its UTF-8 byte length.

The nine-point size comparison

The expansion chart applies the same length formulas to nine hypothetical input sizes. With N equal to the current encoded image's byte count and i running from 0 through 8, each sampled size is rounded to the nearest whole byte, with halfway values rounded upward.

ni=⌊N×i4+12⌋

The range runs from zero to twice the current size. The fifth point equals the current image size and carries the markers. Each point compares binary bytes, padded Base64 text bytes, and complete Data URI bytes using the current prefix. Small inputs can produce repeated rounded sample sizes. No additional images are resized or encoded to obtain these points, so the chart measures neither compression quality nor visual quality.

Delivery-fit rules

These practical bands compare the complete unwrapped Data URI length D. A length at or below the first cutoff receives Fits well. Above that cutoff and at or below the second receives Review size. Anything above the second receives External file preferred. The cutoffs are guidance authored for this converter, not limits defined by the Base64 or Data URI standards.

Inclusive Data URI character cutoffs for each delivery recommendation
DestinationFits well maximumReview size maximum
CSS background12,00032,000
HTML image24,00090,000
Email HTML32,00080,000
JSON or API120,000400,000

Best current fit chooses the strongest available status. Equal statuses are resolved in the fixed order CSS, HTML, email, then JSON. It does not compare loading speeds or inspect the destination. Choosing a specific destination keeps the recommendation tied to that destination.

Rendering changes before encoding

Optional image rendering produces a still image before Base64 conversion. PNG preserves the rendered pixels and supports transparency; JPEG fills transparent areas with the chosen background; WebP output depends on browser encoding support. A quality setting of 100 does not guarantee lossless output or original bytes. The reported output format follows what the browser actually produces, and rendering can make the file larger.

For a positive maximum long edge, both dimensions are scaled by the requested maximum divided by the original long edge only when the original is larger. Each result is rounded to the nearest pixel and kept at least one pixel. A 640 × 360 image with a 160-pixel maximum therefore becomes 160 × 90. Zero disables resizing. When comparing rendered results, keep the source, dimensions, format, quality, background, and browser consistent, and inspect fine detail, colors, and transparency.

Restoration syntax and validation

Restoration accepts raw standard Base64 or an image Data URI whose header ends in ;base64 immediately before the comma. Simple media-type parameters such as ;charset=utf-8 may precede that marker. ASCII spaces, tabs, carriage returns, line feeds, and form feeds are ignored around the input and within the payload. This does not extend to arbitrary Unicode whitespace.

After removing permitted whitespace and any terminal padding, a final group of two characters needs ==, three needs =, and a complete group of four needs neither. Missing terminal padding is restored when the group is otherwise valid. A one-character final group, misplaced or excessive padding, and partially supplied padding are rejected. The last character must also have four unused zero bits for a two-character ending, or two unused zero bits for a three-character ending. Rejection of nonzero tail bits prevents acceptance of a noncanonical ending.

Base64URL symbols, percent-encoded Data URIs, non-image declarations, and extraction from HTML or CSS are unsupported. After text validation, bytes are restored directly and checked for PNG, JPEG, WebP, GIF, BMP, ICO, AVIF, or SVG headers. Declared and detected types are compared independently. A disagreement produces a notice and a download using the detected type, with no image conversion.

Restoration and preview have different resource limits. Staying within a size limit allows the relevant check to proceed; it does not prove that the image is complete or displayable.

Restoration, rendering, and preview limits with inclusive maximums
ItemMaximum or condition
Restored or rendered image bytes64 MiB; the image must be nonempty.
Pasted restoration text96 MiB of accepted ASCII text, including whitespace and any Data URI header.
Data URI text before the comma1,024 ASCII characters, including data:.
Restored image preview5 MiB, checked dimensions no greater than 12,000 pixels on either side, and no more than 40,000,000 pixels in total.
SVG XML inspection for preview2 MiB; larger SVG files can be recognized from the root and namespace within the first 5 MiB, with preview withheld.

AVIF restoration supports downloading the original bytes, but AVIF preview is withheld because its dimension information is not inspected here. SVG document type or entity declarations also withhold XML parsing and preview. Explicit SVG dimensions accept positive decimal values with an optional px suffix. Percentages, physical units, scientific notation, and other unchecked forms prevent preview. When width or height is absent, a positive corresponding viewBox dimension is used when available, otherwise 300 pixels for width or 150 for height.

A recognized image that exceeds a preview limit, has unknown dimensions, or cannot be displayed by the browser remains downloadable. An unrecognized header is rejected. Header checks do not validate every image structure or predict all rendering costs, and a failed preview alone cannot establish that the file is corrupt.

Privacy and File Safety:

Image encoding, optional rendering, and byte restoration happen locally in the browser. Image files, generated payloads, and pasted Base64 are not uploaded or included in the page URL. Preferences can be reflected in the URL, including direction, encoding settings, and alt text, so avoid putting confidential information in those preference fields.

  • Switching direction retains each source in the current tab. Changes to the input or direction stop older work from replacing a newer result. Clear removes the restoration input and result; Remove image removes the encoder source and result.
  • Reloading can restore preferences, but it does not restore a selected local image or pasted Base64. Clipboard contents and downloaded files are separate copies that remain under your control.
  • Chart display can require a network connection to load supporting software. If it fails, check the connection and select Retry chart. This network loading does not upload the image content.

SVG preview uses an image context, where scripts and external resource loading remain inactive. The downloaded SVG is not sanitized: its original scripts, foreign content, and external references remain in the bytes. Opening it directly as a document or embedding it in another context can permit different behavior. Treat an unfamiliar restored file according to its origin; a successful conversion is not a security scan.

Worked Examples:

Preserving the generated SVG

With optimization off and Data URI MIME label left blank, the encoder's 640 × 360 SVG sample contains 706 bytes. It produces 944 raw Base64 characters and a 970-character Data URI, with 33.7% raw overhead displayed. Wrapping the raw text at 64 columns gives 958 characters; 76 columns gives 956. Those added line breaks do not change the summary's unwrapped counts. Paste the raw text or complete Data URI into the reverse direction to restore the same 706 image bytes.

The prefix changes a size recommendation

For a PNG image containing 9,000 bytes, raw Base64 has 12,000 characters. Its 22-character prefix makes the Data URI 12,022 characters long, so CSS receives Review size. HTML, email, and JSON still receive Fits well, and Best current fit selects HTML because it is first among those tied statuses. Test the intended destination before deciding to embed the image.

Restoring a mislabeled image

If a complete SVG payload arrives with an image/png Data URI label, pasting it into Base64 → image can still restore the SVG. Detected format shows image/svg+xml, Declared type shows image/png, and the mismatch notice explains the difference. Downloading saves the unchanged SVG bytes as SVG. Correct the declaration at its origin if that Data URI will be reused.

References: