K082 / Encoding and decoding
Base64
An encoding scheme converting binary data into printable text.
CRYPTOGRAPHY LAB / K082
Cryptography Lab · Base64
Run real computations and inspect intermediate states step by step.
Educational only. Never enter real passwords or secret keys. Computation stays in your browser; input and trace values are not sent to a server. Do not use this implementation in production.
Base64 (RFC 4648)
See the scope above for fixed examples, reduced parameters and supported variants. Standard operation names and formulas are retained.Output
Previous state
- Definition and overview
- An encoding scheme converting binary data into printable text. Source document ↗
- Classification and reversibility
- A reversible encoding, not encryption or hashing; the encoded value can be restored to the original bytes. Source document ↗
- Key or secret requirements
- No key or secret is required because this is not encryption; the encoded value alone suffices for recovery. Source document ↗
- Operating principle and structure
- Splits three input bytes (24 bits) into four six-bit groups and maps them to 64 characters. Source document ↗
- Key size, block size and parameters
- No key or block-cipher parameters; encoding parameters include the standard alphabet and padding, URL-safe variants (-, _) and omitted or ignored padding. Source document ↗
- Security strength and recommendation
- No cryptographic security strength; cannot protect confidentiality. Source document ↗
- Known attacks and vulnerabilities
- Variants and optional padding across standards are known to cause security and interoperability issues. Source document ↗
- Standards and certification
- Standard documents include RFC 4648 and its revision draft (draft-josefsson-rfc4648bis). Source document ↗
- Typical uses
- Used to carry binary data in text-based environments such as serialization protocols, the web, logging and MIME email. Source document ↗
- Implementations, libraries and tools
- Available through language-specific libraries and modules such as @oslojs/encoding, Python base64 and Rust base64. Source document ↗
- Decryption or decoding
- Interpret the Base64 string as six-bit values and reassemble the original bytes; use a decoder matching the padding rules. Source document ↗
- Advantages
- Useful for transmitting binary data in environments that accept only text. Source document ↗
- Limitations and cautions
- Increases length by approximately 33%; provides neither encryption nor compression. Source document ↗
- Distinguishing encryption, encoding and hashing
- Do not mistake Base64 for encryption or hashing; it provides no confidentiality protection. Source document ↗
Practical examples
Example
Encoding a binary file as Base64 produces an ASCII string; decoding returns the original bytes. Example: 'Man' → 'TWFu'.
Procedure
For encoding, group original bytes into three-byte (24-bit) units, split into four six-bit values, map to alphabet characters and append '=' padding as needed. For decoding, reverse the mapping to six-bit values and reassemble bytes using a decoder compatible with the standard or URL-safe variant and padding rules.
Scenario
Used for binary data in email or MIME attachments and text-only APIs. Use base64url for URLs and filenames, and define decoder input validation and padding rules.
Pitfalls and alternatives
Do not use Base64 for confidentiality by mistaking it for encryption. Length grows by about 33%, and variant or padding mismatches can cause compatibility and security problems. Use it only as a transport encoding and encrypt sensitive information separately.
References
- Introduction to Zig - 4 Project 1 - Building a base64 encoder/decoder ↗
- How Base64 works: bits, padding, and URL-safe encoding | base64.date ↗
- The TCP/IP Guide - MIME Content-Transfer-Encoding Header and Encoding Methods ↗
- Base64 - Glossary | MDN ↗
- Base64 Malleability in Practice ↗
- draft-josefsson-rfc4648bis-01 ↗
- Base64 encoding ↗
- Understanding and implementing Base64 ↗
- base64 - Rust ↗
- Binary Encodings ↗