SimdBase64

A blazing-fast C# library for WHATWG forgiving-base64 decoding — up to 2.3× faster than the accelerated .NET functions and 3.8× faster than Convert.FromBase64String, using AVX2, SSE and ARM NEON.

2.6×
faster than accelerated .NET base64 (Apple M2)
3.8×
faster than Convert.FromBase64String
3
SIMD back-ends: AVX2, SSE4.2, NEON
0
allocations — decodes directly into your buffer

Drop-in replacement

SimdBase64 decodes base64 into a buffer you own. It accepts both Span<byte> (ASCII / UTF-8) and Span<char> (UTF-16) input, skips allowable white space, validates the input, and reports exactly how many bytes it consumed and wrote.

using System.Buffers;
using SimdBase64;

string base64 = "SGVsbG8sIFdvcmxkIQ=="; // could be a Span<byte> of UTF-8 too
byte[] buffer = new byte[Base64.MaximalBinaryLengthFromBase64(base64.AsSpan())];

OperationStatus status = Base64.DecodeFromBase64(
    base64.AsSpan(), buffer,
    out int bytesConsumed,
    out int bytesWritten,
    isUrl: false); // true for the base64url alphabet

// status == OperationStatus.Done
ReadOnlySpan<byte> answer = buffer.AsSpan(0, bytesWritten);
// Encoding.UTF8.GetString(answer) == "Hello, World!"

Already calling Convert.FromBase64String? Swap in the accelerated version with a one-line change:

byte[] bytes = SimdBase64.Base64.FromBase64String(s);

The right SIMD kernel is selected automatically at runtime: ARM64 NEON, AVX2, SSE4.2 / SSSE3, or a portable scalar fallback.

SIMD-accelerated

Decodes blocks of base64 at once with vector instructions — the same algorithm shipped in simdutf and used by Node.js and Bun.

🧭

Runtime dispatch

One call, the best available kernel. AVX2, SSE4.2, ARM NEON or a scalar fallback — chosen for your CPU.

🧹

WHATWG forgiving

Handles allowable white space and padding, and validates the input — implementing the WHATWG forgiving-base64 decode rules.

🍏

x64 & ARM

First-class support for modern Intel/AMD and Apple Silicon / Graviton processors.

How fast is it?

Decoding throughput against the accelerated .NET functions (System.Buffers.Text.Base64.DecodeFromUtf8) on the enron email corpus. Longer bars are faster — SimdBase64 in purple, the .NET standard library in grey.

Apple M2 (NEON)
10 GB/s
3.8
2.6×
Intel Ice Lake
7.6 GB/s
3.4
2.2×
AMD EPYC (Zen 2)
6.9 GB/s
3.0
2.3×
AWS Graviton 3
5.1 GB/s
2.0
2.6×

Against the unaccelerated Convert.FromBase64String, the gap is even larger — 3.6×–3.8×. See the full set of measurements in the benchmarks.

Build it

git clone https://github.com/simdutf/SimdBase64.git
cd SimdBase64/src
dotnet build -c Release

Then add a project reference to src/SimdBase64.csproj. Head to the getting started guide or dive into the API reference.

Citing

The algorithms are described in:

Wojciech Muła, Daniel Lemire, Base64 encoding and decoding at almost the speed of a memory copy, Software: Practice and Experience 50 (2), 2020.

Wojciech Muła, Daniel Lemire, Faster Base64 Encoding and Decoding using AVX2 Instructions, ACM Transactions on the Web 12 (3), 2018.