Free .NET developer tool
Base64 Encoder & Decoder
Encode and decode Base64 and URL-safe Base64Url with UTF-8 text, turn files into Base64, and convert GUIDs to 22-character short IDs — byte-for-byte what Convert produces.
Runs entirely in your browser — nothing you paste is uploaded.
SGVsbG8sIC5ORVQhIPCfkYsgw5xuw69jw7Zkw6kgd29ya3MgdG9vLg==File to Base64
Read locally with the File API — the file is not uploaded. Up to 10 MB.
GUID ↔ Base64 (short GUID)
Paste a GUID to get its Base64 forms, or a 22/24-character Base64 ID to get the GUID.
| Base64 | jiocb007X06aCxwtPk9aaw== |
|---|---|
| Short GUID | jiocb007X06aCxwtPk9aaw |
Base64 in C#
Base64 turns bytes into text, so text must first become bytes — always with an explicit encoding, normally Encoding.UTF8. Every three bytes become four characters, so Base64 is about 33% larger than the original.
using System.Buffers.Text;
using System.Text;
string text = "Hello, .NET!";
string b64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(text)); // SGVsbG8sIC5ORVQh
string back = Encoding.UTF8.GetString(Convert.FromBase64String(b64));
// URL-safe (JWTs, query strings, file names) — .NET 9+
string url = Base64Url.EncodeToString(Encoding.UTF8.GetBytes(text));
byte[] raw = Base64Url.DecodeFromChars(url);
// Files
string fileB64 = Convert.ToBase64String(await File.ReadAllBytesAsync("logo.png"));
string dataUri = $"data:image/png;base64,{fileB64}";Short GUIDs
A GUID's 16 bytes encode to 24 Base64 characters, the last two always ==. Drop the padding and use the URL-safe alphabet for a 22-character ID that fits in a URL. Note that Guid.ToByteArray() stores the first three groups little-endian, which this tool matches.
// 22-character URL-safe short ID from a GUID, and back
static string ToShortId(Guid g) =>
Convert.ToBase64String(g.ToByteArray()).TrimEnd('=').Replace('/', '_').Replace('+', '-');
static Guid FromShortId(string s) =>
new(Convert.FromBase64String(s.Replace('_', '/').Replace('-', '+') + "=="));Frequently asked questions
How do I Base64 encode a string in C#?
Convert the string to bytes with an explicit encoding, then encode the bytes: Convert.ToBase64String(Encoding.UTF8.GetBytes(text)). To decode, reverse it: Encoding.UTF8.GetString(Convert.FromBase64String(base64)). Always state the encoding; Encoding.Default differs between .NET Framework and modern .NET.
What is Base64Url and when should I use it?
Base64Url replaces "+" with "-" and "/" with "_", and usually omits the "=" padding, so the result can sit in a URL, file name or JWT without escaping. In .NET 9 and later use System.Buffers.Text.Base64Url.EncodeToString; earlier, use WebEncoders.Base64UrlEncode from Microsoft.AspNetCore.WebUtilities, or Convert.ToBase64String followed by the character replacements.
Why does Convert.FromBase64String throw FormatException?
The input contains characters outside the Base64 alphabet, has the wrong length, or has misplaced padding. The usual culprits are Base64Url input (with "-" and "_"), missing "=" padding, a data: URI prefix, or a "+" that became a space when the value passed through a URL query string. This tool tolerates all of those and tells you which one it found.
How do I make a short 22-character GUID?
Base64-encode the GUID’s 16 bytes and drop the two "=" padding characters, using the URL-safe alphabet: Convert.ToBase64String(guid.ToByteArray()).Replace("/", "_").Replace("+", "-")[..22]. Note that ToByteArray uses .NET’s mixed-endian byte order, so other platforms will produce a different short string for the same GUID unless they use the same order.