Tidy Dev Tools

Base64 Encode

Turn text into Base64. Type or paste — the result updates instantly.

Encoded 45 bytes into 60 characters

Base64
SGVsbG8sIFdvcmxkISBaYcW8w7PFgsSHIGfEmcWbbMSFIGphxbrFhCDwn5iA

Updates as you type. Ctrl+Enter (⌘+Enter on Mac) in the input processes immediately and jumps to the first error.

When to encode to Base64

Base64 lets you put bytes where only text is allowed: data: URLs for small images, JSON fields that carry file contents, HTTP Basic authentication headers and e-mail attachments. Encoded data is about 33% larger than the original, so it is a transport format, not a storage format.

Choose the URL-safe alphabet in the ⋯ menu for tokens in URLs and file names. It replaces + and / with - and _ and drops the = padding, exactly as JSON Web Tokens do.

The tool works with any Unicode text: it converts text to UTF-8 bytes first, so accented letters and emoji survive the round trip. It runs entirely in your browser; nothing is sent to a server.

How Base64 works

The encoder takes three bytes (24 bits) at a time and splits them into four groups of six bits. Each group picks one of 64 characters: A–Z, a–z, 0–9, plus two symbols. The word Man becomes TWFu. When the input length is not a multiple of three, one or two = signs pad the final block.

The scheme is defined in RFC 4648, which also specifies Base32 and Base16. Older software follows RFC 2045 (MIME), whose decoders silently skip unexpected characters — convenient, but it can hide corrupted transfers. Choose the strict variant whenever both sides are under your control.

Encoding in code

  • JavaScript: btoa() accepts only Latin-1, so convert first: btoa(String.fromCharCode(...new TextEncoder().encode(text))). In Node, use Buffer.from(text).toString('base64').
  • Python: base64.b64encode(text.encode('utf-8')).decode(), or urlsafe_b64encode for the URL variant.
  • Shell: printf %s 'text' | base64. Plain echo adds a newline that ends up encoded too.

Base64 is not encryption. Anyone can decode it, so never use it to hide passwords or keys.

Questions

How much bigger does the output get?

Four characters for every three input bytes, rounded up: 1 KB becomes about 1.37 KB. MIME e-mail adds a line break every 76 characters, which costs a little more.

Why does the same text encode differently elsewhere?

Usually because of a hidden newline, a different character set such as Windows-1250 instead of UTF-8, or the URL-safe alphabet. Compare the byte counts shown in the status line.

Can I encode an image or PDF here?

This page encodes text. For files, use a file-to-Base64 converter or base64 picture.png in a terminal, then prefix the result with the correct MIME type for a data URL.