How Base64 turns binary into text, step by step
By TechCompare · Updated · How we check
Base64 encoding is a straightforward 3-to-4 byte expansion with optional padding. Understanding the algorithm helps you debug encoding issues and explains why Base64 output is always a multiple of 4 characters. For practical use, rely on your language's standard library rather than implementing it yourself.
Base64 encoding takes arbitrary binary data and produces text using a 64-character alphabet (A-Z, a-z, 0-9, +, /). The algorithm processes input 3 bytes (24 bits) at a time, splits them into four 6-bit groups, and maps each group to a character in the alphabet. Every 3 bytes of input produce exactly 4 characters of output.
How this is calculated
When the input isn't a multiple of 3 bytes, Base64 adds padding. One extra byte produces two Base64 characters plus == padding. Two extra bytes produce three Base64 characters plus = padding. The = characters signal to the decoder how many padding bytes to strip.
Some variants (URL-safe Base64, AWS Signature V4) omit padding entirely because the length of the encoded string already implies the original length. The algorithm is deterministic and reversible: the same input always produces the same output, and decoding always recovers the original bytes.
Verdict
Use your language's standard library, because the algorithm is fixed and reversible. Every 3 input bytes become exactly 4 characters, and = padding fills any leftover tail so the output length is always a multiple of four.
More Encoding scenarios
Related guides
Frequently asked questions
How does Base64 turn binary data into text?
Why does Base64 output end with = or ==?
Is Base64 encryption or encoding?
Related tools
JSON Formatter
Validate, format, and minify JSON. Browse it as a tree, run JSONPath queries, compare two documents, or validate against a JSON Schema.
Use toolUnix Timestamp
Convert between Unix timestamps and human-readable dates.
Use toolCron Generator
Visually build standard 5-part cron expressions or translate them into readable schedules.
Use tool