Base64 Encoder / Decoder
Base64 is an encoding scheme that represents binary data using only 64 printable ASCII characters, making it safe to transmit through systems that only handle text. It increases the data size by about 33%, so it is not a compression tool. Use it whenever you need to embed images, keys, or binary payloads inside JSON, HTML attributes, or email headers.
What Is Base64 Encoding?
Base64 is a binary-to-text encoding scheme that converts arbitrary binary data — images, files, cryptographic keys, raw bytes — into a string of 64 printable ASCII characters. The name comes directly from the mathematics: each Base64 digit represents exactly 6 bits of data, so three bytes of input (3 × 8 = 24 bits) map neatly to four Base64 characters (4 × 6 = 24 bits). The resulting string uses only the characters A–Z, a–z, 0–9, +, and /, with = used as padding when the input length is not a multiple of three.
The formal specification lives in RFC 4648, published by the Internet Engineering Task Force. Section 4 of that document defines the standard Base64 alphabet, while Section 5 defines the URL-safe variant that replaces + with - and / with _ — the form you will encounter inside JSON Web Tokens and many modern APIs.
It is crucial to understand what Base64 is not. It is not encryption. It is not compression. It adds no confidentiality whatsoever: anyone who receives a Base64 string can decode it in seconds with a free tool or a single line of code. Its sole purpose is to make binary data safe for text-only channels — HTTP headers, JSON payloads, XML documents, email bodies — that would otherwise corrupt or reject raw binary. The encoding carries a size cost of roughly 33 per cent: three bytes become four characters, so a 100 KB image becomes approximately 133 KB when Base64-encoded.
Base64 became ubiquitous through email. The MIME standard — which governs how email clients attach files and embed content — relies on Base64 to transmit binary attachments through email servers that were originally designed to handle only 7-bit ASCII text. Every time you open an email with an image in the body or a PDF attached, Base64 encoding is almost certainly involved somewhere in that transmission chain.
In modern web development, Base64 appears in data URIs (the data:image/png;base64,... pattern embedded in HTML and CSS), in HTTP Basic Authentication headers where the username and password are joined with a colon and Base64-encoded, in JWT tokens, in TLS certificates, and in countless API integrations that need to carry binary payloads inside JSON fields. Understanding when and why to use it — and when not to — is a foundational skill for any developer working with web APIs.
How to Use the Base64 Encoder / Decoder
- Choose your operation. Select either Encode or Decode from the mode toggle. Encoding converts plain text or binary data into a Base64 string. Decoding converts a Base64 string back into its original form.
- Enter your input. Paste your text, credentials, token, or any other string into the input field. For encoding, this is the raw content you want to convert. For decoding, paste the Base64-encoded string — it will consist entirely of alphanumeric characters,
+,/, and possibly trailing=padding signs. - Select the character set if needed. For most text-based content, UTF-8 is correct. If you are working with legacy systems that use a different encoding, select accordingly. Getting the character set wrong is one of the most common sources of garbled output.
- Click Encode or Decode. The result appears instantly in the output field. No data is sent to any server; the conversion happens entirely in your browser.
- Copy the result. Use the copy button to grab the output cleanly, without trailing whitespace or newline characters that could break downstream systems.
- For URL-safe Base64, use the appropriate variant option if your tool offers it. This replaces
+with-and/with_, making the output safe to include in URLs and filenames without percent-encoding.
Why Use This Tool
Browser-based Base64 encoding and decoding handles the tasks developers face daily without requiring them to open a terminal, write a script, or install software. When you are debugging an API response at 11 pm and need to decode a JWT payload, or when you need to encode a service account key to paste into a CI/CD environment variable, a fast online tool saves meaningful time.
Privacy is an important consideration. Unlike server-based tools, a client-side encoder performs all conversions locally using the browser's built-in btoa() and atob() functions — the standard JavaScript APIs documented on MDN Web Docs. Your API keys, credentials, certificates, and tokens never leave your machine. For anyone working with sensitive configuration data, this distinction matters.
The tool handles both directions of the conversion in a single interface, which is more convenient than maintaining separate bookmarks for encoding and decoding. It also handles edge cases that trip up manual attempts: correct padding with = characters, proper handling of Unicode input, and accurate output for binary content represented as text.
For developers integrating with third-party APIs, Base64 encoding is a constant companion. REST APIs that accept file uploads in JSON bodies typically require the file content to be Base64-encoded. OAuth flows pass Base64-encoded client credentials in the Authorization header. SMTP servers and email APIs encode attachments before transmission. Having a reliable, instant tool for these operations reduces friction and eliminates guesswork about whether your encoding is correctly formed.
Real-World Use Cases
HTTP Basic Authentication. The HTTP Basic Authentication scheme requires the client to send credentials in the format Authorization: Basic <credentials>, where credentials is the Base64 encoding of username:password. If your username is myapp and your password is s3cr3t, you encode myapp:s3cr3t to get bXlhcHA6czNjcjN0 and send that in the header. Many developers use a Base64 tool to construct and verify these headers when testing APIs with cURL or Postman.
JWT token inspection. JSON Web Tokens consist of three Base64URL-encoded sections separated by dots: a header, a payload, and a signature. The header and payload are standard Base64URL, meaning you can decode them with any Base64 decoder (treating - as + and _ as /). Decoding the payload reveals the claims — user ID, roles, expiry timestamp, issuer — which is invaluable when debugging authentication failures. The signature section is cryptographic and cannot be forged, but decoding the payload is completely safe and extremely informative.
Embedding images in HTML and CSS. Small images, icons, and logos can be embedded directly into HTML or CSS as data URIs using the pattern src="data:image/png;base64,<encoded-data>". This eliminates an HTTP request for the resource and is useful for critical above-the-fold images in performance-sensitive contexts, or for single-file HTML documents that must be self-contained. Base64-encoded images are larger than the originals, so this technique is best reserved for small assets where eliminating a network round-trip outweighs the size increase.
API payloads containing binary data. JSON does not have a native binary type. When a REST API needs to accept or return binary content — a PDF generated server-side, a scanned document, a signing certificate — the convention is to Base64-encode the binary and carry it as a string field in the JSON body. Developers building integrations with document management systems, e-signature platforms, and file storage APIs encounter this pattern constantly.
Environment variables and secrets management. Multi-line values such as TLS certificates, SSH private keys, and service account JSON files are difficult to store in environment variables that expect single-line strings. Base64-encoding the file produces a compact single-line string that can be stored in a CI/CD secret, an environment variable, or a Kubernetes secret. The application then decodes it at runtime. This pattern is standard in Docker-based deployments and cloud platforms such as Heroku, Render, and Railway.
Email attachments via SMTP APIs. Transactional email services such as SendGrid, Mailgun, and AWS SES accept file attachments as Base64-encoded strings in their API payloads. When building automated reports, invoice delivery systems, or notification emails with attachments, you first read the file, Base64-encode its binary content, and include the encoded string in the API request alongside the filename and MIME type.
Debugging obscured data in network traffic. Security professionals and QA engineers reviewing network requests frequently encounter Base64-encoded payloads in HTTP requests and responses. Being able to quickly decode these strings without leaving the browser is useful during penetration testing, security audits, and integration testing. Recognising Base64 in network traffic is also a defensive skill: malware and data exfiltration tools sometimes encode payloads to avoid simple pattern-matching detection.
Configuration files and infrastructure as code. Tools such as Ansible, Terraform, and Kubernetes accept Base64-encoded values for secrets, certificates, and binary configuration blobs. Kubernetes secrets store all values as Base64-encoded strings in YAML manifests. Infrastructure engineers frequently need to encode and decode these values when writing or auditing Kubernetes manifests and Helm charts.
Common Mistakes and Troubleshooting
Confusing encoding with encryption. This is the most consequential mistake someone can make with Base64. Encoding a password, API key, or personal data in Base64 provides zero security. It is trivially reversible. If you need to protect data, use proper encryption (AES-256, RSA, or similar). Base64 is for compatibility, not confidentiality. Security audits routinely flag Base64-encoded secrets found in source code or logs, because the data is effectively in plaintext.
Mixing standard and URL-safe variants. Standard Base64 uses + and /; URL-safe Base64 uses - and _. If a decoder expecting standard Base64 receives URL-safe input, it will fail or produce garbage. JWT tokens use URL-safe Base64 without padding. When decoding a JWT payload in a standard Base64 decoder, you need to replace - with + and _ with / first, and add any missing = padding to make the length a multiple of four.
Padding errors. Standard Base64 output length is always a multiple of four, achieved by appending one or two = characters. Some implementations strip this padding for compactness. If your decoder returns an error about invalid input length, try appending = characters until the string length is divisible by four. Conversely, some decoders reject strings with padding where none is expected — know which flavour your system uses.
Double-encoding. If you Base64-encode a string that is already Base64-encoded, decoding it once gives you Base64 text rather than the original data. You then need to decode twice. This happens frequently in automated pipelines where multiple stages each apply their own encoding without checking whether the data is already encoded. If your decoded output looks like valid Base64 rather than meaningful content, try decoding again.
Character set and Unicode problems. Base64 encodes bytes, not characters. If your input contains non-ASCII characters (accented letters, emoji, CJK characters), the encoder must first convert the string to bytes using a specific character encoding — almost always UTF-8 on modern systems. If the encoder and decoder use different character encodings, the decoded output will be garbled. Always ensure both ends of the pipeline agree on the character encoding, and when in doubt, use UTF-8.
Whitespace in Base64 strings. Some systems insert line breaks into Base64 output every 76 characters (as specified in the MIME standard) or every 64 characters. When copying a Base64 string from an email client, a certificate file, or a multi-line environment variable, stray newlines and spaces may be present. Most decoders reject whitespace by default. Strip all whitespace from a Base64 string before decoding if you are getting unexpected errors.
Expecting Base64 to reduce file size. Base64 increases data size by approximately 33 per cent. It is not a compression algorithm. If you need to reduce file size, compress the data first (using gzip or similar), then Base64-encode the compressed bytes if a text-safe format is required. Doing it in the wrong order — Base64 first, then compress — is less efficient because Base64 output is less compressible than the original binary.
S. Siddiqui
Founder & Editor-in-Chief, YourToolsBase
How encoding a single string saved me an afternoon of OAuth debugging
When I was wiring up an OAuth 2.0 client credentials flow for a third-party analytics API, the authentication kept failing with a 401 even though I was certain the credentials were correct. The API docs said to send the client_id and client_secret as a Base64-encoded Authorization header in the format client_id:client_secret. I had encoded the string myself in a quick script, but something was off. I pasted both the raw string and the encoded output into this tool and immediately saw the problem: my script had produced URL-safe Base64 with hyphens and underscores, while the header required standard Base64 with plus signs and forward slashes, as defined in RFC 4648 Section 4.
On top of that, the padding was being stripped. The tool showed me the correct padded output with the trailing equals signs intact, and it also showed me that my raw string had a trailing space I had not noticed, which was being encoded into the payload and breaking the match on the server side. I stripped out the space, switched to standard Base64, and the 401 resolved straight away.
In practice, the difference between URL-safe and standard Base64 only surfaces when you are passing encoded data inside HTTP headers or query strings, which is exactly where most OAuth flows live. Having a tool that lets you toggle between the two variants and inspect the raw output is far quicker than reading spec documents when you are already 40 minutes into a debugging session.
Frequently Asked Questions
What is Base64 encoding used for?
Is Base64 encoding the same as encryption?
Why does Base64 use the equals sign (=) at the end?
What is the difference between Base64 and Base64URL?
How much larger does data get when Base64-encoded?
Can I decode a JWT token with a Base64 decoder?
Why does my Base64 decoder show garbled text?
What are the atob() and btoa() JavaScript functions?
Is it safe to use an online Base64 tool for sensitive data?
What is Base64 encoding in email?
∑ Formula
Rate This Tool
Was this tool helpful?
Be the first to rate this tool
💡 Pro Tip
Never store passwords in Base64 — it's encoding, not encryption. Anyone can decode it instantly. Use bcrypt or Argon2 for password storage.
About the Author
S. Siddiqui is the founder and editor-in-chief of YourToolsBase, overseeing all content, tool accuracy, and editorial standards.
View full profileAuthoritative Sources
Formulas and data in this tool are based on guidelines from the above sources.