Base64 Encoder / Decoder

Encode plain text to Base64 (RFC 4648) or decode standard Base64 content back to readable text.

By Pankaj Kumar · DevToolsHub · Last updated Jun 2026

How to encode or decode Base64 online

  1. Paste plain text into the input editor to encode it, or paste a Base64 string to decode it.
  2. Click Encode or Decode — use the Switch to decode/encode button to change modes.
  3. If the decoded output looks like JSON, use the Format in JSON Formatter shortcut to pretty-print it in one click.
  4. 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

VariantCharacters 62–63PaddingWhere you see it in .NET
Standard (RFC 4648 §4)+ and /= requiredConvert.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:

AspectEncoding (Base64)Encryption (AES)Hashing (SHA-256)
Reversible?Yes — always, by design, no key neededYes — only with the correct keyNo — one-way by design
Requires a secret/key?NoYesNo (a keyed variant, HMAC, exists for verification)
PurposeSafe transport of binary data as textConfidentiality — hide data from anyone without the keyIntegrity — detect if data changed; store passwords safely
.NET APIConvert.ToBase64String / FromBase64StringSystem.Security.Cryptography.AesSystem.Security.Cryptography.SHA256
Output size vs input~33% larger than the inputSame order of magnitude, padded to a block sizeFixed length regardless of input size (256 bits for SHA-256)

Five real .NET use cases

  1. 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 with Convert.FromBase64String before passing to the X509Certificate2 constructor.
  2. Constructing an HTTP Basic Auth header in HttpClient without using a credentials cache. Format: new AuthenticationHeaderValue("Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes("user:pass"))). Set it on DefaultRequestHeaders.Authorization before sending requests.
  3. 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.
  4. 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.FromBase64String to see the raw JSON header or payload.
  5. 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.

This tool is built with ASP.NET Core 8, Blazor Server, and System.Convert. It runs securely on Microsoft Azure.

Native code equivalents

Production-ready snippets — same logic the tool runs, in your language
Your data is processed within your active session only · Never stored or logged
JavaScript
Python
Go
cURL / bash
// 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');
Input Section

Text or Base64 input

Hello DevToolsHub
Output Section

Base64 result

Output