A file-to-Base64 example is simple: a file whose exact content is the six ASCII bytes foobar encodes as the canonical Base64 string Zm9vYmFy.

Base64 converts arbitrary bytes into printable characters so binary data can pass through systems designed to carry text. It does not interpret the file, change its format, or make it safe. For a browser-based workflow, the File to Base64 Converter reads the selected file's exact bytes, keeps processing in the current browser tab, and does not send the name, type, or contents to the server. It supports source and decoded files up to 10,000,000 bytes.

Base64 is reversible encoding rather than encryption. Anyone with the encoded text can recover the bytes, so the result should be handled with the same sensitivity as the original file.

file to base64 example
File to Base64 Example: Encode and Decode a Local File

A minimal file-to-Base64 example

Create a file named example.txt and make its entire content foobar. Do not add a newline, UTF-8 byte-order mark, or trailing spaces: each one would add bytes and change the encoded result.

The worked size calculation is: bytes ÷ 3 = groups, then groups × 4 = characters. Substituting the file size gives 6 ÷ 3 = 2 groups and 2 × 4 = 8 characters. The result is Zm9vYmFy, with no = padding because no partial three-byte group remains.

This rule applies to arbitrary binary files as well as short text files. The encoder preserves every byte, including zero values and bytes that are not valid text. It does not inspect or rewrite the file format, normalize line endings, transcode images, or interpret metadata.

The copied output contains only Base64 characters and required padding. It does not include the original filename, a MIME header, a data URL prefix, or line wrapping. Add any of those containers only when the destination's specification explicitly requires them.

Canonical Base64 values to recognize

The RFC 4648 Base64 specification defines the standard alphabet and padding rules. Canonical Base64 uses the characters A–Z, a–z, 0–9, plus sign, and slash. When the final group contains fewer than three bytes, equals signs complete the output, and the unused pad bits must have zero values.

RFC 4648 input vector Canonical Base64 output
empty stringempty string
fZg==
foZm8=
fooZm9v
foobZm9vYg==
foobaZm9vYmE=
foobarZm9vYmFy

A one-byte remainder receives two equals signs, while a two-byte remainder receives one. These padding characters are part of the canonical value and should not be trimmed. The converter's encoder also produces unwrapped output, so the copied text contains no spaces or line breaks.

Encode a local file with the converter

  1. Confirm the required profile. Make sure the destination expects standard RFC 4648 Base64. If it specifies Base64url, a data URL, MIME line wrapping, or omitted padding, convert the output to that profile separately.
  2. Choose the file. Select a source file no larger than 10,000,000 bytes, then verify its displayed name and size before continuing.
  3. Read the exact bytes. The browser's File API supplies an ArrayBuffer from the selected file, preserving binary values instead of first converting the content to displayable text.
  4. Copy the complete output. Retain any trailing equals signs. The converter does not silently truncate its canonical output.
  5. Paste it into the destination. Insert a prefix, MIME declaration, filename, or wrapping format only when the receiving application documents that requirement.

The copied value is suitable for a raw Base64 field. It is not automatically a data URL, and adding a familiar prefix can prevent another decoder from recognizing it.

Decode Base64 into a downloadable file

  1. Obtain the raw payload. If the text is inside a data URL, remove the container only when you know its structure and need the underlying payload. The converter does not accept a data URL prefix.
  2. Check the canonical rules. Use the standard alphabet with plus sign and slash, include all required equals padding, remove whitespace, and ensure unused pad bits are zero. The decoder rejects alternate non-canonical spellings.
  3. Paste the payload in reverse mode. Switch the converter to the Base64-to-file direction and paste the complete string into the input field.
  4. Set the download metadata. Enter the intended filename and MIME type based on the known file format. They control the download suggestion and Blob media type, but they do not inspect or modify the bytes.
  5. Decode, download, and validate. Open the generated download in an appropriate application to check its real format. When integrity matters, compare it with a known cryptographic hash.

Malformed input never produces a partial download link. After a successful conversion, the page creates a Blob URL that exists only in the current browser session. It is revoked when a newer conversion replaces it or the converter closes.

Match the Base64 profile your destination expects

Several text formats contain Base64 but are not accepted directly by the strict decoder:

  • Base64url: Convert its alphabet and padding profile explicitly before submitting it.
  • MIME line wrapping: Remove line breaks according to the profile's specification before decoding.
  • Data URL: Separate the known prefix and metadata from the underlying canonical payload first.
  • Omitted padding: Restore the required equals signs explicitly before decoding.

Do not guess a file type from the first few Base64 characters. Although some formats begin with recognizable character sequences, Base64 itself carries bytes rather than a guaranteed file-format declaration.

Limits and safe handling

Base64 expands binary data by roughly one third, and the browser may hold the byte array, Base64 string, and rendered output together. The converter therefore limits both source and decoded files to 10,000,000 bytes. Larger files are better handled with streaming command-line or application workflows.

  • Local processing boundary: The application does not upload the selected file's name, type, or contents. Browser extensions, device malware, clipboard managers, downloaded-file handlers, and the destination into which you paste the output remain outside that boundary.
  • No safety guarantee: Base64 does not encrypt, hash, sign, compress, sanitize, or scan files. It can contain malware, credentials, private data, or executable bytes.
  • Potential exposure: Encoded data can appear in logs, tickets, source code, and analytics. Some content remains recognizable even though it has been encoded.
  • Untrusted devices: Avoid sensitive files on a device you do not trust, because local processing cannot control the rest of the system.
  • Post-download validation: A filename and MIME type are labels only. Validate the downloaded bytes with the correct application and, where integrity matters, a cryptographic hash.

For the simplest file-to-Base64 example, the exact file content foobar produces Zm9vYmFy. For real files, confirm the byte content, Base64 profile, destination requirements, and downloaded result before relying on the conversion.

Related reading: Is a Hill Cipher Decoder Safe? Local Processing Explained.

Related reading: Unescape HTML: Decode Entities to Plain Text.