Developer Tools

How to Encode Text and Files to Base64

By Habib ur Rehman · Updated July 2026 · 7 min read

Base64 strings appear in API responses, email attachments, JSON Web Tokens, data URIs, and configuration files. They can look like random characters, but Base64 is simply a way to represent data using text characters that most systems can handle. This guide explains how Base64 encoding works, when to use it, how the 33% size increase happens, and why Base64 should not be confused with encryption.

What Base64 Encoding Actually Does

Base64 takes any kind of data — text, images, PDFs, audio — and converts it into a string of 64 printable ASCII characters. The character set includes uppercase A-Z, lowercase a-z, digits 0-9, plus sign (+), and forward slash (/). The equals sign (=) appears at the end as padding when needed.

The purpose is practical: many systems were designed to handle plain text. Email protocols, JSON APIs, HTML documents, XML files — these systems can struggle with raw binary data. Base64 acts as a bridge. It converts binary into text that travels safely through text-only channels, and the recipient converts it back when needed.

Original Text: Hello, World!

Base64 Encoded: SGVsbG8sIFdvcmxkIQ==

Where You Encounter Base64

Email Attachments

When you attach a photo or PDF to an email, the email client encodes the attachment as Base64 before sending it. The recipient's email client decodes it back automatically. You never see the Base64 string in normal use, but it is visible if you view the raw email source. The MIME standard governing this is defined in RFC 2045.

HTTP Basic Authentication

When a browser or application accesses a password-protected API, it combines the username and password with a colon (username:password) and Base64 encodes the result. This encoded string is sent in the Authorization header. Anyone who intercepts the request can decode it — which is why Basic Auth must always be used over HTTPS, never over plain HTTP.

JSON Web Tokens (JWT)

JSON Web Tokens use Base64URL encoding for their header and payload sections. Base64URL is closely related to Base64 but uses URL-safe characters and may omit padding. A JWT has three dot-separated parts — the first two are Base64URL-encoded JSON. Developers routinely decode these sections during debugging to inspect what claims the token contains. The JWT standard is defined in RFC 7519. Important: Decoding a JWT shows its contents but does not verify its authenticity — signature verification is a separate step.

Data URIs in HTML and CSS

Small images and icons can be embedded directly in HTML or CSS as Base64 data URIs. Instead of linking to an external file, the image data is included directly in the page. This can reduce HTTP requests for very small assets. A data URI looks like this:

Data URI Example: <img src="data:image/png;base64,iVBORw0KGgo...">

The Size Trade-Off

Base64 encoding makes data approximately 33% larger. This is a mathematical result of how the encoding works, not a bug. Every 3 bytes of original data are split into 4 groups of 6 bits. Each 6-bit group maps to one of 64 characters. Three bytes in, four characters out — a 33% increase.

For small amounts of data — short text strings, authentication tokens, tiny icons — this increase is negligible. For large files, it adds up noticeably. This is why Base64 is generally not recommended for encoding large files unless there is a specific reason to do so.

Original SizeApproximate Base64 SizeIncrease
100 bytes~136 bytes~36%
1 KB~1.37 KB~37%
1 MB~1.33 MB~33%
10 MB~13.3 MB~33%

Base64 Is NOT Encryption

This is one of the most common misunderstandings about Base64. Base64 is encoding — it transforms data into a different format for transmission. It provides no security. Anyone with a Base64 decoder can reverse it instantly.

If you need to protect sensitive data, use actual encryption such as AES-256. If you need to safely transmit data through text-based systems, Base64 can help with that. They serve completely different purposes. Do not confuse them. Do not use Base64 to store passwords, API keys, private tokens, or confidential information.

How to Encode Text to Base64

The Base64 Encoder tool is designed to process supported input in your browser where supported. Review the tool page for current processing, privacy, and compatibility details. Here is how to use it:

  1. Open the Base64 Encoder page
  2. Type or paste your text into the input area
  3. The tool encodes supported text input — the Base64 output appears in real time
  4. Click Copy to grab the encoded string, or Download to save it as a .txt file

For decoding Base64 strings back to text, use the Base64 Decoder.

Encoding Files Like Images or PDFs

For text, the encoding process is straightforward. For binary files such as images, PDFs, or ZIP archives, the browser first reads the file into memory, then the data can be Base64 encoded. The Base64 Encoder can handle compatible local files when the browser supports reading them. Very large files may take longer, use significant browser memory, or exceed device capabilities.

Encode Text to Base64 Now

Convert supported text input to Base64 directly in your browser.

Open Base64 Encoder

Important Limitations

  • Base64 is encoding, not encryption. Do not use it to protect passwords, API keys, or confidential data.
  • Base64 output is approximately 33% larger than the original input.
  • Very large files can use substantial browser memory and may process slowly or fail.
  • Base64URL (used in JWTs) differs slightly from standard Base64 — it uses URL-safe characters and may omit padding.
  • Decoding a JWT shows its contents but does not verify its signature or authenticity.
  • Check the Base64 Encoder tool page for current supported input types, privacy details, and browser compatibility.

Common Questions

What is Base64 encoding used for?

Converting text or binary data into a text-based format that can travel through systems designed for plain text. Common in email attachments, JWT tokens, HTTP Basic Auth, data URIs, and some API or configuration workflows.

Is Base64 the same as encryption?

No. Base64 is encoding — it transforms data for transmission. It provides no security. Anyone can reverse it without a key. Use encryption such as AES-256 when data needs to be protected.

Why does Base64 make my data larger?

It uses only 64 characters to represent all 256 possible byte values. Every 3 bytes become 4 characters — approximately a 33% size increase. This is the trade-off for safe text-based transmission.

Can I Base64 encode any file?

Text, images, PDFs, and other compatible local files can be encoded when the browser can read them. The output is a string of printable ASCII characters. Very large files may be affected by browser memory limits.

How do I decode Base64 back to text?

Use the Base64 Decoder. Paste the Base64 string and it converts back to the original bytes or readable text. Encoding and decoding are complementary — one converts to Base64, the other converts back.

Explore Related Developer Tools