ToolSpotAI

Base64 Encoder & Decoder

Encode UTF-8 text to Base64 or decode Base64 back to text in your browser—handles Unicode and ignores whitespace when decoding.

Developer
Advertisement

What is Base64 Encoder & Decoder?

Base64 is a way to represent arbitrary bytes using only printable ASCII characters. Developers use it when binary data must travel through systems that only handle text—JSON fields, PEM certificates, data URLs in HTML, or email attachments described inline. Encoding does not hide information; it only changes the representation. For UTF-8 text, the correct workflow is to convert the string to UTF-8 bytes first, then Base64-encode those bytes. Older examples sometimes misuse btoa with Unicode strings and break emoji or accented letters; a proper tool encodes the full Unicode text as UTF-8 before applying Base64. Our encoder and decoder run entirely in your browser. You can switch between encoding plain text to a Base64 string and decoding a Base64 string back to readable UTF-8 text. When decoding, whitespace and line breaks are ignored so values copied from email or formatted documents still work. This matches how people debug APIs, inspect tokens, or prepare small payloads for documentation and tests.

How It Works

For encoding, we take your input string and use the TextEncoder API to produce a UTF-8 byte sequence. Those bytes are turned into a binary string that btoa accepts, and btoa outputs standard Base64. For decoding, we remove whitespace from your input, use atob to obtain a binary string, convert those bytes back with a Uint8Array, and TextDecoder produces the final UTF-8 string. If atob fails—wrong characters, bad padding, or truncated input—we show the browser error message so you can fix the paste.

Formula

UTF-8 bytes = TextEncoder.encode(text)

Encode:   Base64 = btoa(bytesAsBinaryString)

Decode:   binary = atob(Base64)

Text = TextDecoder.decode(Uint8Array from binary)

Formula Explained

JavaScript’s btoa and atob are defined for “binary strings” where each character code is a byte (0–255). Unicode strings must be converted to UTF-8 bytes first; TextEncoder and TextDecoder are the standard way to do that in modern browsers. Base64 maps every 3 bytes to 4 characters, with = padding when the length is not a multiple of 3. That is why encoded output is longer than the original text. Decoding is the inverse: four Base64 characters map back to three bytes, then UTF-8 decoding interprets those bytes as a string.

Example

Plain text (UTF-8): Hello — 世界 Encoded (example): SGVsbG8g4oCUIOeUnOe6v+eUsQ== Decoding that Base64 string returns the same original text. Invalid input (bad character): SGVsbG*v — contains * which is not valid Base64; decode fails with an error.

Tips & Best Practices

  • When pasting from PDFs or chat apps, invisible characters can break decode—try retyping the Base64 or paste into a plain-text editor first.
  • Very large inputs can slow down the browser; for huge files prefer desktop or CLI tools.
  • Remember Base64 is not encryption—do not use it to protect secrets.
  • JWT payloads are Base64URL; replace - with + and _ with / before using standard decoders if needed.
  • Line-wrapped PEM blocks: strip headers/footers and concatenate the Base64 body before decoding the inner DER.

Common Use Cases

  • Decoding small Base64 blobs from API responses during debugging
  • Encoding snippets for data URLs or inline configuration samples
  • Checking whether a string is valid Base64 before feeding it to other tools
  • Learning how UTF-8 and binary-safe encoding work together
  • Preparing test vectors for tutorials and documentation

Frequently Asked Questions

Base64 is an encoding that represents binary data using 64 ASCII characters (A–Z, a–z, 0–9, +, /). It is often used to embed binary data in text-only formats such as JSON, email, or data URLs. It is not encryption—anyone can decode it.

Yes. We encode your input as UTF-8 bytes, then Base64 those bytes. Decoding reverses the process so emoji and international characters round-trip correctly.

Common causes include invalid characters (only A–Z, a–z, 0–9, +, /, and padding = are standard), wrong padding length, or corrupted copy-paste. This tool strips whitespace and line breaks before decoding to help with pasted blocks.

No. Encoding and decoding run entirely in your browser with JavaScript. Nothing is uploaded to ToolSpotAI.

This tool uses standard Base64 (+ and /). Some APIs use Base64URL (- and _ instead, no padding). If you need that variant, replace characters accordingly or use a dedicated Base64URL option where available.

Related tools