← Guides

Developer Guide

Convert Text to Base64

Encode UTF-8 text to Base64 in the browser. Covers padding, Unicode and emoji, URL-safe mode, and when to use an image converter instead.

text to base64convert text to base64string to base64encode text base64utf-8 base64

Base64 is not a cipher and it is not compression. It writes arbitrary bytes using 64 ASCII characters so the result can sit in JSON, a header, or a query string. For text, encode the string to UTF-8 bytes first, then map those bytes to the alphabet.

/tools/base64 does both in the browser. Type hello in Encode mode and you get aGVsbG8=, including the padding =. This page is the encode direction. Decoding — padding, URL-safe alphabets, and garbage that was never text — lives on the Base64-to-text guide.

UTF-8 first, then the 64-character alphabet

JavaScript strings are Unicode. Base64 is defined on bytes. The converter runs TextEncoder (UTF-8) and then packs every three bytes into four characters from A–Z a–z 0–9 + /.

ASCII is a one-byte-per-character subset, which is why hello (five bytes) encodes so short. A Devanagari letter or an emoji is multiple UTF-8 bytes, so the Base64 is longer than the visible character count. नमस्ते becomes 4KSo4KSu4KS44KWN4KSk4KWH. 👋🌍 becomes 8J+Ri/CfjI0=. If a library encodes as Latin-1 instead of UTF-8, those strings will not round-trip.

Why the output ends with =

Three input bytes become four output characters. When the byte length is not a multiple of three, the encoder pads with = so the string length stays a multiple of four.

One leftover byte needs two padding characters (a → YQ==). Two leftover bytes need one (hi → aGk=). hello is five bytes, remainder two, so one =: aGVsbG8=. Padding is part of the encoding, not decoration. Do not strip it unless the receiver asked for the URL-safe variant that omits it on purpose.

Unicode, emoji, and what “text” means here

Anything you can type in the textarea is text. Combining marks, right-to-left scripts, and emoji all go through UTF-8. The output will contain + and / whenever those bytes land in those alphabet slots — 👋🌍 already has a + in 8J+Ri/CfjI0=.

Paste the characters, not HTML entities or \uXXXX escapes, unless those backslashes are literally in the string you want to encode.

URL-safe mode

Standard Base64 uses + and /, which are special in URLs and in some filenames. Check URL-safe on /tools/base64 to emit - and _ instead, and to drop padding. <<??>> is PDw/Pz4+ in standard form and PDw_Pz4- in URL-safe form. 👋🌍 becomes 8J-Ri_CfjI0 with the checkbox on.

Use that mode for query parameters, JWT-style tokens, and filenames. Do not send URL-safe output to a decoder that only accepts +/ and =. The same checkbox on decode maps the alphabet back.

When not to use this converter

Do not paste a PNG into a text encoder. The bytes are not UTF-8 text. Use /tools/image-to-base64 for a file. That tool emits a data URI with a data:image/TYPE;base64, prefix. The reverse tool /tools/base64-to-image requires that prefix — raw payload alone is not enough.

Do not encode megabyte-sized logs here either. Base64 grows data by about a third (four characters per three bytes) and the browser holds the whole string in memory. Gzip if you need size; encode only if a text channel requires it.

Common pitfalls

Encoding twice (aGVsbG8= encoded again) is a real bug in copy-paste pipelines. The second output is valid Base64 of the first output, not of hello. Swap to Decode on /tools/base64 if the “text” already looks like A–Z a–z 0–9 + /.

Treating Base64 as a secret is the other mistake. aGVsbG8= is hello in public. Encoding credentials for HTTP Basic Auth is a transport convention, not confidentiality.

  • hello → aGVsbG8= on /tools/base64 Encode.
  • Images belong on /tools/image-to-base64, not this page.
  • URL-safe changes +/ and drops =; only use it when the other side agrees.

Worked examples

ASCII text

Input
hello
Output
aGVsbG8=

Five UTF-8 bytes, remainder two, so one padding =. Encode this on /tools/base64.

Greeting with a space and punctuation

Input
Hello World!
Output
SGVsbG8gV29ybGQh

Length is a multiple of three bytes, so there is no padding. Decode is on the companion guide.

Emoji (UTF-8, then Base64)

Input
👋🌍
Output
8J+Ri/CfjI0=

URL-safe Encode yields 8J-Ri_CfjI0 — same bytes, different alphabet, no padding.

Frequently asked questions

Is Base64 the same as encryption?

No. Anyone can decode aGVsbG8= back to hello. Encoding makes bytes text-safe. Encryption needs a key.

Why is the result longer than my text?

Every three bytes become four characters, so the payload grows by about a third, plus any = padding. That expansion is the encoding, not a bug.

Can I encode a JPEG here?

Not usefully. Use /tools/image-to-base64 so you get data:image/jpeg;base64,…. /tools/base64 is for Unicode text.

Does thedevtools.in upload what I type?

No. Encode runs with TextEncoder and btoa in your tab. There is no encoding API on the server.

When do I turn on URL-safe?

When the string will sit in a URL, a filename, or a JWT-style token. Leave it off for MIME, JSON fields that expect standard Base64, and data URIs.

Summary

Encode text by going UTF-8 then Base64, keep the padding unless you opted into URL-safe, and stop at /tools/base64 for strings. Files and photographs go through /tools/image-to-base64. To read a string back, switch the same tool to Decode or open the Base64-to-text guide.

Try it yourself

Put what you've learned into practice with our free browser-native tool.

Open Tool →