Base64
Encode text to Base64 or decode Base64 strings back to readable content. Supports full Unicode including accented characters, emoji, and non-Latin scripts. All processing happens in your browser.
Key features
- Fast conversion from text to Base64 and vice versa
- Swap button moves the result into the input and switches the mode
- Shows \
- when a string cannot be decoded to text
- One-touch copy of all content
Guide
Base64 encoding converts binary data into a text-safe format using 64 ASCII characters (A-Z, a-z, 0-9, +, /). It is one of the most widely used encoding schemes in software development, appearing in email attachments, data URIs, API authentication, JWT tokens, certificate files, and configuration systems. This tool encodes text to Base64 and decodes Base64 back to text in your browser.
What Base64 Is and Is Not
Base64 is an encoding, not encryption. It transforms data into a different representation but provides zero security. Anyone can decode a Base64 string instantly. Never use Base64 to protect sensitive information. If you see a password or API key encoded in Base64, it is no more secure than storing it in plain text. A common misconception among junior developers is that encoding credentials in Base64 somehow hides them. It does not.
The encoding works by taking every 3 bytes of input and converting them into 4 ASCII characters. Each character represents 6 bits of data (2^6 = 64 possible values). This means Base64 output is always about 33% larger than the input. A 3KB file becomes approximately 4KB when Base64-encoded. The padding character = appears at the end when the input length is not a multiple of 3. One byte of input (not divisible by 3) results in two Base64 characters plus == padding. Two bytes result in three Base64 characters plus = padding.
The standard character set is: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/. A variant called Base64URL replaces + with - and / with _ to make the output safe for URLs and filenames. This variant is used in JWT tokens and other URL-embedded data. The distinction matters because + and / have special meaning in URLs (+ is sometimes treated as a space, / is a path separator).
The Encoding Process Step by Step
To understand Base64, walk through encoding the string "Hi" (two bytes: 0x48 and 0x69).
Step 1: Convert each byte to binary. H = 01001000, i = 01101001. Step 2: Concatenate all bits: 01001000 01101001. Step 3: Split into 6-bit groups: 010010 000110 1001. Since we only have 16 bits (not divisible by 6 evenly), pad the last group with zeros: 010010 000110 100100. Step 4: Map each 6-bit group to the Base64 alphabet. 010010 = S, 000110 = G, 100100 = k. Step 5: Add padding. We started with 2 bytes (not a multiple of 3), so add one = character. Result: SGk=
This is exactly what btoa("Hi") returns. Understanding this process helps when you debug encoding mismatches.
Encoding Text to Base64
The most basic operation: you have a string and need its Base64 representation. In JavaScript, this is btoa("Hello World") which returns "SGVsbG8gV29ybGQ=". The tool does this in real-time as you type.
A critical detail: btoa() only handles ASCII characters (code points 0-255). If your string contains non-ASCII characters like emojis, accented letters (cafe), or CJK characters, btoa() throws an error. The correct approach in JavaScript is:
For encoding: btoa(unescape(encodeURIComponent(text))) For decoding: decodeURIComponent(escape(atob(base64)))
The modern approach uses TextEncoder: btoa(String.fromCharCode(...new TextEncoder().encode(text))). This tool handles Unicode correctly, so you can paste any text including non-Latin characters and emoji.
Practical example: you need to set a Basic Authentication header. The format is Authorization: Basic base64(username:password). If your username is admin and password is s3cret, you encode admin:s3cret to get YWRtaW46czNjcmV0. The full header becomes Authorization: Basic YWRtaW46czNjcmV0. You can generate this directly in the tool. Every HTTP client that supports Basic Auth does this encoding internally, but when debugging raw HTTP traffic, you need to decode the header manually to see the credentials.
Decoding Base64 to Text
Paste a Base64 string and get the original text back. This is the operation you perform most often when debugging. You see a Base64 string in a log file, a JWT payload, an email header, or a config value, and you need to know what it says.
For example, you receive a webhook payload where the body field is eyJldmVudCI6Im9yZGVyLmNyZWF0ZWQiLCJpZCI6MTIzfQ==. Decoding it reveals {"event":"order.created","id":123}. Without a decoder, you are either going to a terminal to run echo ... | base64 -d or writing a throwaway script.
If the input decodes to binary data (an image, a certificate, a compressed payload) rather than UTF-8 text, this tool shows "Invalid Base64 input" instead of garbled characters. That happens because the tool decodes the bytes as UTF-8, and binary data is rarely valid UTF-8. To decode a binary file, use the command line: base64 -d input.txt > output.bin.
Another common scenario: you find a Base64 string in a Kubernetes Secret manifest. Running kubectl get secret my-secret -o json shows values like cGFzc3dvcmQxMjM=. Decoding reveals password123. This is why Kubernetes Secrets are not truly secret without additional encryption (like sealed-secrets or external secret managers).
Encoding and Decoding Files
Base64 file encoding converts any binary file into a text string. This is used for:
Data URIs: embedding images directly in HTML or CSS. An image tag like <img src="data:image/png;base64,iVBOR..." /> loads without a separate HTTP request. This is useful for small images (icons, logos under 5KB) to reduce network requests. For CSS, you can embed backgrounds: background-image: url(data:image/png;base64,...). Build tools like Webpack can automatically inline small images as data URIs.
Email attachments: MIME encoding uses Base64 to embed binary attachments in text-based email protocols. When you attach a PDF to an email, your email client Base64-encodes the file, adds Content-Transfer-Encoding: base64 header, and embeds the encoded text in the email body. The recipient's client decodes it back to a PDF.
JSON payloads: when an API needs to accept file uploads as JSON fields, the file is typically Base64-encoded. For example, uploading a profile photo as {"avatar": "data:image/jpeg;base64,..."}. GitHub's API uses this approach for creating and updating file contents in repositories.
Configuration storage: embedding small files (SSL certificates, SSH keys, service account JSON) in environment variables or config management systems that only support text values. Heroku config vars, AWS Systems Manager parameters, and Docker secrets all store text, so binary content needs Base64 encoding.
This tool works with text only. It has no file input and no download button. To encode a file, use the command line commands listed in the languages section below, or a script in your language of choice. To decode Base64 back to a file, use the same commands in reverse.
When to Use Base64 (and When Not To)
Use Base64 when you need to transmit binary data through a text-only channel. Email, JSON, XML, URL parameters, environment variables, CSV fields, and many database text fields are text-only. Base64 bridges the gap between binary data and text-safe representation.
Do not use Base64 when you have a binary-safe transport. HTTP supports binary uploads via multipart/form-data. S3, Azure Blob Storage, and GCS accept binary uploads directly. gRPC supports binary fields natively. Using Base64 in these contexts adds 33% overhead for no benefit.
Do not use Base64 for large files. A 10MB image becomes 13.3MB when Base64-encoded. If you embed that in JSON, the JSON parser has to load the entire string into memory, decode it, and then process the binary. For files larger than a few kilobytes, use a direct file upload endpoint or a pre-signed URL. Cloud storage pre-signed URLs let clients upload files directly to S3/GCS without passing through your API server.
Do not use Base64 for security. Base64-encoded credentials in a config file are visible to anyone who opens the file. Kubernetes Secrets store values as Base64, but this is for encoding (handling arbitrary bytes), not encryption. You still need proper secret management (HashiCorp Vault, AWS Secrets Manager, Azure Key Vault).
Do not embed Base64 images in HTML for images larger than 2-3KB. While data URIs eliminate an HTTP request, they cannot be cached independently and increase the HTML document size. For images above this threshold, serving them as separate files with proper cache headers is more efficient.
Base64 in Different Programming Languages
JavaScript (browser): btoa() and atob() for ASCII strings. For Unicode, use the TextEncoder/TextDecoder approach or the Buffer class in Node.js.
Node.js: Buffer.from(text, 'utf-8').toString('base64') for encoding. Buffer.from(base64, 'base64').toString('utf-8') for decoding. For Base64URL: Buffer.from(text).toString('base64url').
Python: import base64; base64.b64encode(b'text').decode() and base64.b64decode('dGV4dA==').decode(). For URL-safe: base64.urlsafe_b64encode() and base64.urlsafe_b64decode().
Java: java.util.Base64.getEncoder().encodeToString(bytes) and Base64.getDecoder().decode(string). For URL-safe: Base64.getUrlEncoder() and Base64.getUrlDecoder().
Go: encoding/base64 package. base64.StdEncoding.EncodeToString(data) and base64.StdEncoding.DecodeString(str). For URL-safe: base64.URLEncoding.
Rust: The base64 crate. base64::encode(data) and base64::decode(str).
PHP: base64_encode($data) and base64_decode($str).
C#: Convert.ToBase64String(bytes) and Convert.FromBase64String(str).
Command line: echo -n 'text' | base64 for encoding, echo 'dGV4dA==' | base64 -d for decoding (use base64 --decode on macOS). The -n flag is important to avoid encoding a trailing newline. For files: base64 input.bin > output.txt and base64 -d input.txt > output.bin.
Common Mistakes
Mistake 1: Forgetting the -n flag when encoding from the command line. echo 'hello' | base64 includes a newline character, producing aGVsbG8K instead of aGVsbG8=. The trailing newline is a real byte that gets encoded. This causes mismatches when comparing with values encoded by your application. Always use echo -n or printf.
Mistake 2: Double encoding. You encode a string, then accidentally encode the result again. The output looks like valid Base64 but decodes to another Base64 string instead of the original text. If decoded text looks like Base64 (contains only letters, digits, +, /, and =), try decoding it one more time. Triple encoding also happens in complex systems where multiple middleware layers each encode the data.
Mistake 3: Mixing Base64 and Base64URL. A JWT payload uses Base64URL encoding (with - and _ instead of + and /), and padding is often stripped. If you paste a JWT segment into a standard Base64 decoder, it may fail or produce wrong output. Replace - with + and _ with / before decoding, and add = padding characters to make the length a multiple of 4.
Mistake 4: Line breaks in Base64 strings. Some encoders insert line breaks every 76 characters (MIME standard, RFC 2045). If you copy a multi-line Base64 string and paste it with the line breaks, the decoder needs to strip them. This tool handles line breaks automatically, but some programmatic decoders do not.
Mistake 5: Encoding the data: URI prefix. If you want a data URI, the format is data:image/png;base64,ENCODED_DATA. Encode only the file content, not the data: prefix. A common bug is running the entire string data:image/png;base64,... through the encoder again.
Mistake 6: Assuming Base64 output is always URL-safe. Standard Base64 contains + and / which have special meaning in URLs. If you put a Base64 string in a URL query parameter without URL-encoding it, the + signs will be interpreted as spaces by most servers. Use Base64URL encoding or URL-encode the Base64 string.
Advanced Tips
When debugging JWT tokens, split the token on the . character to get three parts: header, payload, and signature. The header and payload are Base64URL-encoded JSON strings. Decode each separately to inspect the claims. The signature is a binary hash and will not produce readable text when decoded.
For embedding small SVG files, you can use a data URI without Base64: data:image/svg+xml,%3Csvg...%3E. URL-encode the SVG instead of Base64-encoding it. This produces a smaller result because SVG is already text. Base64 adds 33% overhead, but URL encoding is more compact for text content that is mostly ASCII.
When storing Base64 in databases, use TEXT or LONGTEXT column types, not VARCHAR with a small limit. A Base64 string for even a small image (10KB) becomes about 13,600 characters. Plan your column sizes for the 33% expansion plus potential MIME line breaks.
If you need to calculate the Base64-encoded size of a file without encoding it: multiply the file size in bytes by 4/3 and round up to the nearest multiple of 4. A 12-byte file produces exactly 16 characters of Base64. A 13-byte file produces 20 characters (with one padding =). The formula is: ceil(n/3) * 4 where n is the input byte count.
For streaming large files, you can encode in chunks as long as each chunk (except the last) is a multiple of 3 bytes. This produces Base64 output that concatenates correctly without padding in the middle. Most streaming encoders handle this automatically.
When comparing two Base64 strings, be aware that they are case-sensitive. aGVsbG8= and AGVSBG8= are completely different values. Also, whitespace and line breaks may differ between two otherwise identical encodings. Strip whitespace before comparing.
Base64 in Real-World Systems
Kubernetes Secrets are the most commonly encountered Base64 use case in DevOps. Every Secret value is stored as Base64. When you run kubectl create secret generic db-creds --from-literal=password=mypassword, Kubernetes encodes the value to bXlwYXNzd29yZA==. When you kubectl get secret db-creds -o yaml, you see the encoded value. This is purely for safe storage of arbitrary bytes in YAML, not for security. Use SealedSecrets, SOPS, or an external secret operator for actual protection.
GitHub Actions secrets are also referenced through Base64 sometimes. When a CI workflow needs to use a service account JSON file, the common pattern is to Base64-encode the JSON file, store the encoded string as a repository secret, then decode it in the workflow: echo "${{ secrets.GCP_SA_KEY }}" | base64 -d > sa-key.json. This avoids issues with multi-line values in environment variables.
SSL/TLS certificates use PEM encoding, which is Base64 with specific headers. A PEM file starts with -----BEGIN CERTIFICATE----- and ends with -----END CERTIFICATE-----. The content between these markers is Base64-encoded DER (binary) certificate data. When you see a PEM certificate, you are looking at Base64.
SMTP email transmission uses Base64 for the entire message body when Content-Transfer-Encoding is set to base64. Every email attachment you have ever sent was Base64-encoded. The MIME standard specifies 76-character line length for Base64 in email, which is why MIME Base64 output has line breaks.
WebSocket communication sometimes uses Base64 for binary frame encoding when the application protocol is text-based. If you are debugging WebSocket messages and see Base64 strings, the application is likely transmitting binary data (images, protobuf, compressed payloads) through a text frame.
Source maps in JavaScript can embed the original source code as Base64. A source map file may contain sourcesContent with Base64-encoded TypeScript or JavaScript source. Inline source maps use data URIs: //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjoz... This embeds the entire source map in the built file.
Performance Considerations
Base64 encoding and decoding are fast operations. On modern hardware, you can encode several gigabytes per second. The performance bottleneck is almost never the encoding itself but the I/O (reading the file, transmitting the larger encoded result, or allocating memory for the string).
In browsers, atob() and btoa() are implemented natively in C++ and are very fast for strings up to several megabytes. For larger data, use the streaming approach with FileReader and process chunks. This tool converts the whole input again on every keystroke, so very long inputs can make typing slow.
Memory usage is the main concern for large Base64 operations. Encoding a 100MB file requires holding the original binary data (100MB), the encoded string (133MB), and temporary buffers in memory simultaneously. In server environments, use streaming encoders that process chunks to avoid holding the entire file in memory.
Base64 Alternatives
Base32 uses 32 characters (A-Z and 2-7) and produces output 60% larger than the input (compared to 33% for Base64). It is case-insensitive and avoids confusing characters, making it suitable for human-readable contexts like OTP secrets (used in Google Authenticator TOTP tokens).
Base85 (also called Ascii85) uses 85 printable ASCII characters and produces output only 25% larger than the input. It is more space-efficient than Base64 but uses characters that are not safe in all contexts. Git uses a variant of Base85 for binary diff encoding. PostScript and PDF use Ascii85 for embedded binary data.
Hex encoding uses 16 characters (0-9 and a-f) and produces output 100% larger than input (each byte becomes two hex characters). It is less efficient than Base64 but more readable and easier to debug. Hash values (SHA-256, MD5) are typically displayed as hex strings.
For binary data in JSON, consider MessagePack, CBOR, or Protocol Buffers as alternatives to JSON+Base64. These binary formats handle binary data natively without the 33% overhead of Base64 encoding.
Frequently asked questions
Is Base64 an encryption?
No. Base64 is an encoding method that converts binary data to ASCII text. It does not provide security.
Does it support Unicode characters?
Yes. All character sets including accented letters, emoji, and non-Latin scripts convert correctly.
