Base64 Encoder / Decoder
Encode plain text to Base64 (RFC 4648) or decode standard Base64 content back to readable text.
How to encode or decode Base64 online
- Paste plain text into the input editor to encode it, or paste a Base64 string to decode it.
- Click Encode or Decode — use the Switch to decode/encode button to change modes.
- If the decoded output looks like JSON, use the Format in JSON Formatter shortcut to pretty-print it in one click.
- Copy the result using the Copy button.
Base64 in .NET daily development
In my .NET work, Base64 comes up in three recurring situations: embedding binary assets in configuration values, inspecting JWT segments by hand, and constructing HTTP Basic Auth headers manually when testing APIs with HttpClient. The .NET standard library handles encoding in one line, but it is easy to misuse — specifically, confusing the standard and URL-safe variants, or forgetting that the 33% size overhead matters when you're storing Base64 in a database column or a cookie.
A field note: the most common Base64 mistake I've seen isn't a decoding bug — it's someone treating a Base64-encoded value as if it were protected, storing an API key or a connection string Base64-encoded in a config file under the assumption that "at least it's encoded." A five-second paste into a decoder proves otherwise. If a value needs to stay secret, it needs real encryption or a secrets manager — Base64 is a text-safe transport format, not a lock.
Base64 in .NET: Convert and System.Buffers.Text
The BCL provides Base64 through System.Convert (available since .NET 1.0) and the newer System.Buffers.Text.Base64 class (added in .NET Core 2.1 for high-throughput span-based scenarios). For most application code, Convert.ToBase64String and Convert.FromBase64String are the right choice:
// Encoding bytes to Base64
byte[] fileBytes = File.ReadAllBytes("report.pdf");
string encoded = Convert.ToBase64String(fileBytes);
// Decoding Base64 back to bytes
byte[] decoded = Convert.FromBase64String(encoded);
File.WriteAllBytes("restored.pdf", decoded);
// Encoding a plain string — always specify the character encoding explicitly
string original = "Hello, DevToolsHub!";
string b64String = Convert.ToBase64String(Encoding.UTF8.GetBytes(original));
string back = Encoding.UTF8.GetString(Convert.FromBase64String(b64String));
// HTTP Basic Auth header: the format is Base64("username:password")
string credentials = "myuser:mypassword";
string headerValue = Convert.ToBase64String(Encoding.ASCII.GetBytes(credentials));
httpClient.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", headerValue);
A common mistake: calling Convert.ToBase64String directly on a string object, which doesn't compile since the method only accepts byte[]. You must encode to bytes first. Use Encoding.UTF8 for general text and Encoding.ASCII for credential strings guaranteed to be ASCII-only.
Standard Base64 vs Base64URL — a critical distinction
| Variant | Characters 62–63 | Padding | Where you see it in .NET |
|---|---|---|---|
| Standard (RFC 4648 §4) | + and / | = required | Convert.ToBase64String, MIME email, data URLs, HTTP Basic Auth |
| URL-safe (RFC 4648 §5) | - and _ | Optional (often omitted) | JWT header and payload, OAuth tokens, Base64UrlEncoder in Microsoft.IdentityModel |
This tool implements standard Base64 only. JWT tokens use Base64URL without padding — pasting a JWT segment directly fails because Convert.FromBase64String does not accept - or _ and requires padding. Use the JWT Decoder for JWT-specific work. To decode a Base64URL segment here manually: replace - with + and _ with /, then add = padding until the length is a multiple of 4.
Base64 is encoding, not encryption
Base64 provides zero security. Decoding is a one-liner: Encoding.UTF8.GetString(Convert.FromBase64String(value)). Never Base64-encode sensitive values as a substitute for encryption. For real protection, use System.Security.Cryptography.Aes for symmetric encryption or Microsoft.AspNetCore.DataProtection for ASP.NET Core-managed key protection of values like tokens and cookies.
These three operations are often confused because all three turn readable data into something that isn't — but they solve completely different problems:
| Aspect | Encoding (Base64) | Encryption (AES) | Hashing (SHA-256) |
|---|---|---|---|
| Reversible? | Yes — always, by design, no key needed | Yes — only with the correct key | No — one-way by design |
| Requires a secret/key? | No | Yes | No (a keyed variant, HMAC, exists for verification) |
| Purpose | Safe transport of binary data as text | Confidentiality — hide data from anyone without the key | Integrity — detect if data changed; store passwords safely |
| .NET API | Convert.ToBase64String / FromBase64String | System.Security.Cryptography.Aes | System.Security.Cryptography.SHA256 |
| Output size vs input | ~33% larger than the input | Same order of magnitude, padded to a block size | Fixed length regardless of input size (256 bits for SHA-256) |
Five real .NET use cases
- Storing a PFX certificate in Azure Key Vault or
appsettings.json. Key Vault secrets are strings. Base64-encode the raw bytes of a PFX file, store the result as a secret, and decode at runtime withConvert.FromBase64Stringbefore passing to theX509Certificate2constructor. - Constructing an HTTP Basic Auth header in
HttpClientwithout using a credentials cache. Format:new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes("user:pass"))). Set it onDefaultRequestHeaders.Authorizationbefore sending requests. - Embedding a small image in an HTML email sent via MailKit or SendGrid. Use a
data:image/png;base64,[encoded]inline URI to avoid broken images in email clients that block external URLs. - Inspecting a JWT segment by hand without a full JWT decoder. Split the token on dots, take the first or second segment, add padding to a multiple of 4, decode with
Convert.FromBase64Stringto see the raw JSON header or payload. - Passing a serialized object as a redirect URL parameter. Serialize to JSON, Base64-encode, then URL-encode. On the receiving side, URL-decode, Base64-decode, then deserialize. Useful for passing state in OAuth redirect flows without server-side session storage.
Frequently asked questions
Why does Convert.FromBase64String throw FormatException on my JWT segment? Three causes: the string contains - or _ characters (Base64URL, not standard Base64), the string length is not a multiple of 4 (missing padding), or there are whitespace characters that weren't stripped. For JWT segments: replace -→+, _→/, and pad to a multiple of 4.
Does Base64 encoding change the character encoding of the original string? No. Base64 encodes bytes, not characters. The bytes you get depend entirely on the character encoding you use to convert the string to bytes first. If you encode with UTF-8 and decode assuming ASCII, non-ASCII characters produce garbage. Always specify the same encoding on both sides.
How does ASP.NET Core handle byte[] properties in JSON by default? System.Text.Json serializes byte[] properties as standard Base64 strings (with = padding) by default. This means a byte[] DTO property appears as a Base64 string in your JSON payloads and can be decoded directly in this tool.
Native code equivalents
Production-ready snippets — same logic the tool runs, in your language// Standard Base64 (RFC 4648 §4) — btoa/atob are latin-1 only
// Use TextEncoder for full Unicode support
const encode = (str) => btoa(unescape(encodeURIComponent(str)));
const decode = (b64) => decodeURIComponent(escape(atob(b64)));
// Base64URL (RFC 4648 §5) — used by JWT tokens
const encodeUrl = (str) =>
btoa(unescape(encodeURIComponent(str)))
.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
const decodeUrl = (b64url) => {
const b64 = b64url.replace(/-/g, '+').replace(/_/g, '/');
const pad = b64.length % 4 === 0 ? '' : '='.repeat(4 - b64.length % 4);
return decodeURIComponent(escape(atob(b64 + pad)));
};
// Node.js 18+
const encoded = Buffer.from('Hello, DevToolsHub!').toString('base64');
const decoded = Buffer.from(encoded, 'base64').toString('utf-8');Text or Base64 input
Hello DevToolsHub
Base64 result
Output