Devkitrdevkitr
Encoding & Security

Base64 Encoding Explained — Why and How It Works

2026-01-206 min read

Base64 encoding is a method of converting binary data into ASCII text. It's widely used in web development for embedding data in URLs, HTML, CSS, and transmitting binary content over text-based protocols.


How Base64 Works


Base64 encoding converts every 3 bytes (24 bits) of binary data into 4 ASCII characters from a set of 64 characters:


  • Uppercase letters: A-Z (26)
  • Lowercase letters: a-z (26)
  • Digits: 0-9 (10)
  • Special characters: + and / (2)
  • Padding character: =

  • The encoding process:

  • Take 3 bytes of input (24 bits)
  • Split into 4 groups of 6 bits each
  • Map each 6-bit value to the Base64 character table
  • If input isn't divisible by 3, add padding (=)

  • Common Use Cases


    Data URIs

    Embed images directly in HTML/CSS:

    <img src="data:image/png;base64,iVBOR..." />


    Email Attachments

    MIME encoding uses Base64 to include binary attachments in text-based email.


    API Authentication

    HTTP Basic Authentication sends credentials as Base64-encoded strings in the Authorization header.


    JWT Tokens

    JWT payloads are Base64URL-encoded (a URL-safe variant of Base64).


    Base64 vs Encryption


    Important: Base64 is NOT encryption. It's an encoding scheme — anyone can decode Base64 data. Never use Base64 alone to protect sensitive information.


    URL-Safe Base64


    Standard Base64 uses + and /, which have special meaning in URLs. URL-safe Base64 replaces these with - and _ respectively.


    Try our Base64 Encoder/Decoder to encode and decode Base64 strings instantly.


    Related Articles

    Back to Blog