Quick Answer
Base64 encoding is a binary-to-text encoding format. It maps bytes into a restricted ASCII alphabet so data can pass through systems that expect text.
Use Base64 when your transport layer is text-first (for example JSON, email, or HTTP headers). Do not use Base64 as a security control: it is encoding, not encryption.
Key Facts
- Base64 uses
A-Z,a-z,0-9,+, and/as symbols. =is padding and may appear at the end.- Output is usually about
4/3of original size (about 33% larger). - Base64URL is the URL-safe variant used in JWTs and OAuth flows.
What Base64 Is and Is Not
Base64 encoding is a representation format.
- It is useful for moving binary data across text systems.
- It is not compression.
- It is not encryption.
- It does not hide sensitive information.
Why Base64 Exists
Many protocols and storage layers were built around text. Raw bytes can be mangled by character set assumptions, delimiter parsing, or transport constraints. Base64 avoids that by emitting plain text characters with predictable handling.
Typical examples:
- MIME email attachments
- JSON APIs that need inline binary blobs
data:URLs in HTML/CSS- HTTP Basic Authorization header values
How Base64 Works
- Read input bytes in groups of 3 bytes (24 bits total).
- Split 24 bits into 4 chunks of 6 bits.
- Map each 6-bit value (0-63) to one Base64 character.
- If input length is not divisible by 3, append
=padding.
Worked Example: Hi
Hi bytes:
H=01001000i=01101001
Combine and split into 6-bit groups:
010010 000110 100100
Map to symbols:
010010=18=S000110=6=G100100=36=k
Input had only 2 bytes, so padding is added to reach 4 output chars:
SGk=
The Size Trade-off
Base64 output length:
encoded_length = 4 * ceil(input_bytes / 3)
Approximate overhead:
size_increase ~= 33%
Example:
- Input:
100 KB - Base64 output:
~133 KB(before gzip/brotli)
This overhead matters for large payloads and mobile bandwidth.
Base64 vs Related Formats
| Format | Primary purpose | Character safety | Typical use |
|---|---|---|---|
| Base64 | Binary to text | Safe for many text channels, not always URL-safe | Email MIME, JSON blobs, headers |
| Base64URL | Binary to URL-safe text | URL-safe (- and _) |
JWT, OAuth PKCE, WebAuthn |
| Hex | Binary to readable text | URL-safe but 2x size | Debugging, checksums |
| Percent encoding | Escapes reserved URL chars | URL component safety | Query strings, path segments |
When to Use Base64 (Decision Rules)
Use Base64 when:
- Binary must live inside a text-only format.
- You need a quick interoperable representation.
- Payload size is small enough that overhead is acceptable.
Avoid Base64 when:
- You can send raw binary directly (multipart/file upload).
- Files are large and network cost matters.
- You need security rather than representation.
Base64 Encoder/Decoder
Encode plain text to Base64 or decode Base64 to readable output in one step.
Open ToolBase64URL: The URL-Safe Variant
Standard Base64 uses symbols that can be awkward in URLs and cookies. Base64URL solves this by replacing:
+with-/with_- optional removal of trailing
=
Common contexts:
- JWT header/payload segments
- OAuth PKCE
code_challenge - WebAuthn IDs and assertions
Base64URL Encoder/Decoder
Convert between standard Base64 and Base64URL for JWT and token workflows.
Open ToolCommon Mistakes
Treating Base64 as security
Anyone can decode Base64 instantly. Use encryption for confidentiality and password hashing for credentials.
Double encoding
Encoding already-encoded output causes integration bugs and invalid payloads. Keep data flow explicit: raw -> encoded -> transmitted -> decoded.
Ignoring character variants
Mixing Base64 and Base64URL without normalization can break signature verification in JWT/OAuth workflows.
Embedding large files in JSON
Large inline Base64 blobs inflate request size and can hit API limits quickly.
FAQ
What is Base64 encoding in one sentence?
Base64 encoding is a binary-to-text encoding method that converts bytes into ASCII characters for safe transport in text-oriented systems.
Is Base64 encryption?
No. Base64 has no key and no secrecy. It is reversible encoding only.
Why does Base64 increase data size by about 33%?
Because each 3 bytes of input become 4 bytes of text output (4/3 expansion), plus optional padding.
Should I use Base64 for passwords?
No. Passwords should be hashed with modern adaptive algorithms. Base64 is not a protection mechanism.
When should I use Base64URL instead of Base64?
Use Base64URL in URL, token, and JWT contexts where +, /, and = may cause compatibility issues.
Can I decode Base64 without losing original bytes?
Yes, if the input is valid and unmodified. Base64 decoding is deterministic.
Is Base64 compressed?
No. Base64 increases size. Compression (gzip/brotli/zip) is a separate step.
What does = mean at the end of Base64?
It is padding used to make output length a multiple of 4 characters.
Related Tools
- Base64 Encoder/Decoder - Encode and decode Base64 strings
- Base64URL Encoder/Decoder - URL-safe Base64 for JWT and OAuth flows
- Image to Base64 Converter - Convert images into Base64 data URIs
- JWT Decoder - Inspect token header and payload segments
- URL Encoder/Decoder - Encode reserved URL characters