Skip to content
ProfitTool
Back to all articles
Developer Tools
1 min read

Base64 Encoding Explained: What It Is and How It Works

Base64 turns binary into 64 safe ASCII characters, at a 33% size cost. How the encoding works, what padding is for, and how Base64URL differs.

ProfitTool Team

Security & Dev

Why Base64 Exists

Many protocols and formats — HTTP headers, JSON, HTML attributes, email bodies — are designed to carry text, not arbitrary binary data. If you try to embed binary data (like an image or a cryptographic key) directly in a text field, the binary bytes may contain control characters or bytes that break the surrounding format.

Base64 solves this by converting binary data into a set of 64 printable ASCII characters, making the data safe to embed anywhere that accepts text.

How It Works

Base64 takes 3 bytes (24 bits) of input and encodes them as 4 characters from a 64-character alphabet:

A-Z (26)  +  a-z (26)  +  0-9 (10)  +  + and /  (2)  =  64 characters

If the input is not a multiple of 3 bytes, = padding characters are appended to make the output length a multiple of 4.

Example:

Input:   "Man"     →  M (77) a (97) n (110)
Binary:  01001101 01100001 01101110
Groups:  010011  010110  000101  101110
Base64:  T       W       F       u      →  "TWFu"

A 3-byte input becomes 4 characters. Every 3 bytes → 4 characters. The encoded size is always ⌈n/3⌉ × 4 bytes.

Base64URL (RFC 4648 §5)

Standard Base64 uses + and /, which are special characters in URLs and file paths. Base64URL replaces them:

  • + → -
  • / → _
  • Padding = is usually omitted

Base64URL is used in JWTs, OAuth tokens, URL-safe tokens, and web API parameters.

Base64 Is Not Encryption

Base64 is an encoding, not encryption. It does not provide any confidentiality. Anyone can decode Base64 instantly without any key. Never use Base64 alone to protect sensitive data.

Use our Base64 Encoder / Decoder to encode and decode both standard Base64 and Base64URL, entirely in your browser.

Tags:#base64#encoding#jwt#developer tools#binary encoding

ProfitTool Team

Security & Dev

Written and maintained by the ProfitTool team. Where an article references a ProfitTool utility, the behaviour described is the behaviour of the tool on this site — you can open it and check the output yourself.