You have a string that looks like `SGVsbG8gd29ybGQ=` and need to know what it says, or you have text, an image, or a small file that must be converted into Base64 for an API, email template, HTML snippet, or JSON payload. After reading this, you’ll know exactly how to encode and decode Base64 online, how to spot the most common formatting problems, and when Base64 is the wrong choice.
Base64 is simple once you understand its limits. It is not encryption, it is not compression, and it is not a file format by itself. It is a text representation of binary data, which makes it useful anywhere plain text is easier to move than raw bytes.
What Base64 is actually used for
Base64 converts data into a limited set of text characters: uppercase letters, lowercase letters, numbers, plus signs, slashes, and sometimes equals signs at the end. That makes it safe to paste into places that may not handle binary data well, such as JSON, XML, HTML, email source, environment variables, or API request bodies.
A few practical examples:
Here is a plain text example:
```text Hello world ```
Encoded as Base64:
```text SGVsbG8gd29ybGQ= ```
That trailing `=` is padding. It helps the decoder understand the final byte group. Not every Base64 string has padding, but if you remove it carelessly, some decoders will reject the string.
The most important thing to remember: Base64 is reversible. Anyone who can see the encoded value can decode it. Do not use Base64 to hide passwords, API keys, private documents, or personal data unless the surrounding system already protects it.
How to encode text to Base64 online
For ordinary text, an online Base64 encoder is the fastest option. The process is usually safe for non-sensitive test strings, sample payloads, HTML snippets, and development work.
Use this workflow:
For example, paste this:
```text Order ID: A-1042 Status: paid Currency: USD ```
The output will be one continuous Base64 string. If the tool wraps the output across multiple lines, look for an option like single line, no line breaks, or raw output. For JSON and most APIs, you usually want one uninterrupted line.
Character encoding matters. If you encode:
```text Café — 東京 ```
with UTF-8, it will decode correctly in modern systems. If you encode it with an older character set and decode it as UTF-8 later, you may see broken characters such as `Café`. When in doubt, use UTF-8 for both encoding and decoding.
For API testing, keep the encoded string inside quotes:
```json { "message": "Q2Fmw6kg4oCUIOadseS6rA==" } ```
Do not add extra spaces before or after the Base64 value. Some decoders tolerate whitespace; others do not.
How to decode Base64 online and check the result
Decoding is just as direct, but you need to know what type of content you expect. A decoded Base64 value may become readable text, or it may become binary data like a PNG, PDF, ZIP, or audio file.
Use this process:
For text, this:
```text SGVsbG8gd29ybGQ= ```
decodes to:
```text Hello world ```
For files, the decoded output may look like unreadable symbols if displayed as text. That does not automatically mean it failed. Binary files are not meant to be read in a text box.
A good clue is the file header after decoding. These are common starting bytes or visible signatures:
If you decode a Base64 string and the result starts with:
```text %PDF-1.7 ```
save it as:
```text document.pdf ```
If it starts with:
```text data:image/png;base64, ```
you are looking at a data URL, not just raw Base64. Remove the prefix before decoding if your tool does not support data URLs:
```text data:image/png;base64,iVBORw0KGgoAAAANSUhEUg... ```
The actual Base64 part begins after the comma:
```text iVBORw0KGgoAAAANSUhEUg... ```
Encoding files, images, and API payloads
Base64 is often used for files, but it is not always the best storage method. It makes the data larger than the original file, and large encoded strings are awkward to copy, log, debug, and store.
For small files, such as a 2 KB SVG icon, a 10 KB PNG logo, or a short certificate file, Base64 is practical. For a 5 MB PDF or a 20 MB video, it is usually better to upload the file directly using multipart form data or object storage, then pass a file URL or ID to your API.
Encoding an image for HTML or CSS
If you want to embed a small image in HTML, the final format should look like this:
```html
```
Use the correct MIME type:
Choose PNG when you need transparency or sharp UI graphics. Choose JPEG for photos where a smaller file matters more than perfect edges. Choose SVG for simple icons and logos when you have vector artwork.
Before Base64-encoding an image, resize or compress it. A 2400 px wide image embedded into HTML is rarely sensible. For email headers and small web graphics, resize logos to something like 300–600 px wide. If the image is decorative inside an email signature, 150–300 px wide is often enough. You can reduce the source file first with Compress Image, then encode the smaller result.
For email attachments, do not paste a Base64 image into the visible body unless you know the email client supports it. Many email systems handle attachments through MIME sections, not simple HTML `img` tags. If you are preparing images for email, use JPG for photos, PNG for logos with transparency, and keep the width near the display size rather than sending a camera-original file.
Encoding files for JSON APIs
Some APIs accept Base64 inside JSON:
```json { "fileName": "invoice.pdf", "mimeType": "application/pdf", "contentBase64": "JVBERi0xLjQKJc..." } ```
Use a clear field name such as `contentBase64`, not just `file`, so future readers know the value is encoded. Always send the filename and MIME type separately if the API supports it. The Base64 string alone does not reliably tell the receiving system what extension to use.
For JSON, avoid line breaks in the Base64 value unless the API documentation explicitly allows them. Some systems accept wrapped lines every 76 characters; others fail because the newline becomes part of the string or breaks parsing.
If your workflow starts with spreadsheet data and ends in an API request, convert the structure cleanly before adding Base64 fields. For tabular payload preparation, a tool like CSV to JSON can help you create valid JSON first, then you can insert the Base64 file value into the correct field.
Common Base64 mistakes and how to fix them
Base64 errors are usually caused by small formatting issues. Here are the ones I see most often in real work.
Mistake 1: Treating Base64 as encryption
If you encode this:
```text password123 ```
you get:
```text cGFzc3dvcmQxMjM= ```
Anyone can decode it in seconds. Use Base64 only for transport or formatting. For secrets, use proper encryption, hashing, password managers, environment secret stores, and HTTPS.
Mistake 2: Copying extra characters
A Base64 string copied from logs may include quotes, commas, labels, or escaped characters.
Bad input:
```text "contentBase64": "SGVsbG8gd29ybGQ=", ```
Correct input:
```text SGVsbG8gd29ybGQ= ```
If decoding fails, paste the string into a plain text editor first. Remove surrounding JSON syntax, quotation marks, backticks, spaces, and trailing commas.
Mistake 3: Leaving the data URL prefix in place
Some decoders accept this:
```text data:image/jpeg;base64,/9j/4AAQSkZJRgABAQ... ```
Others only accept:
```text /9j/4AAQSkZJRgABAQ... ```
If the tool says “invalid character” and the string starts with `data:`, remove everything before and including the comma.
Mistake 4: Using the wrong Base64 variant
Standard Base64 uses `+` and `/`. URL-safe Base64 uses `-` and `_` instead.
Standard:
```text abc+def/ghi= ```
URL-safe:
```text abc-def_ghi ```
If a value comes from a URL, JWT, OAuth flow, or web token, it may be URL-safe Base64. Some online decoders have a setting called Base64URL, URL-safe decode, or web-safe Base64. Use that instead of forcing standard Base64.
JWTs are a common example. They look like three Base64URL sections separated by periods:
```text header.payload.signature ```
You can decode the header and payload for inspection, but do not edit and reuse the token unless you understand signing. Changing the decoded content invalidates the signature.
Mistake 5: Broken padding
Base64 often ends with one or two equals signs:
```text TQ== TWE= TWFu ```
If padding is missing, some decoders still work, but strict ones fail. If you see an error like “incorrect padding,” try adding `=` until the total length is divisible by 4.
Examples:
```text SGVsbG8 ```
Length is 7, so add one `=`:
```text SGVsbG8= ```
Do not randomly add padding to a string that already decodes correctly. Padding is a fix for missing characters at the end, not a general repair tool.
Mistake 6: Decoding binary as text
If a decoded image appears as messy symbols, save it as a file instead of viewing it as text. Use the expected extension: `.png`, `.jpg`, `.pdf`, `.zip`, or whatever the original content should be.
If you do not know the file type, inspect the first few decoded characters. `%PDF` means PDF. `PK` often means ZIP or Office files such as `.docx` or `.xlsx`, since those formats are ZIP-based internally.
Troubleshooting checklist for invalid Base64
When an online decoder rejects your input, work through this checklist in order:
A truncated Base64 string is not repairable unless you can get the missing characters from the original source. If the middle of a long value contains `...`, that is a display abbreviation, not real Base64.
Privacy and safety when using online Base64 tools
Use online tools for public or low-risk content: sample text, test JSON, placeholder images, public logos, documentation examples, and development payloads. Be careful with private documents, customer files, authentication tokens, medical records, contracts, and secret keys.
If the content is sensitive, use an offline command-line tool instead. On macOS or Linux, you can encode a file with:
```bash base64 invoice.pdf > invoice.txt ```
Decode it with:
```bash base64 --decode invoice.txt > invoice.pdf ```
On some macOS versions, decoding may use:
```bash base64 -D -i invoice.txt -o invoice.pdf ```
For Windows PowerShell, you can encode a file with:
```powershell [Convert]::ToBase64String([IO.File]::ReadAllBytes("C:\files\invoice.pdf")) | Set-Content "C:\files\invoice.txt" ```
And decode it with:
```powershell [IO.File]::WriteAllBytes("C:\files\invoice.pdf", [Convert]::FromBase64String((Get-Content "C:\files\invoice.txt" -Raw))) ```
Online tools are convenient, but local commands are better when the data must stay on your machine.
Practical wrap-up
Use Base64 when you need to move text or small binary files through systems that expect plain text, such as JSON, HTML, CSS, or email source. Keep strings on one line for APIs, use UTF-8 for text, remove data URL prefixes before decoding when needed, and remember that Base64 is not encryption.
If your Base64 work is part of a file or API workflow, prepare the source data cleanly first. For example, compress images before encoding them, or structure your API payload with CSV to JSON before adding Base64 file fields.