Upload a file
  1. base64hub
  2. Text tools
  3. Text to Base64

Text to Base64: Convert a String to Base64

Type a string and get its Base64 at once. The result depends on the bytes, so the tool lets you choose the charset and shows the exact byte count it encoded.

Free no sign-up, no limits Local nothing uploaded Updated Oct 27, 2026
Input 0 BOutput 0 BSize –

Processed in your browser. This page cannot send your data anywhere – how we know

How to convert text to Base64

  1. Type or paste the string into Input · text. Whatever you enter is encoded exactly, including spaces and line breaks.
  2. The Base64 appears in Output · Base64. The Input figure below the buttons shows how many bytes your text became.
  3. Leave Charset on UTF-8 unless the system that will decode the value expects something else.
  4. Tick URL-safe (- _) and No padding (=) if the string goes into a URL or a token.
  5. Press Copy output, or Download to save it as base64.txt.

To go back, use Base64 to text, or press Swap to decode the result right here.

One string, several possible Base64 values

Base64 encodes bytes, and a string becomes bytes only through a charset. That is why the same five letters can produce four different answers:

StringCharsetBytesBase64
GrüßeUTF-87R3LDvMOfZQ==
GrüßeWindows-1252 or ISO-8859-15R3L832U=
GrüßeUTF-16LE10RwByAPwA3wBlAA==
GrüßeUTF-16BE10AEcAcgD8AN8AZQ==

Invisible characters count as well. Hello is SGVsbG8=, Hello with a trailing space is SGVsbG8g, and Hello followed by a Windows line ending is SGVsbG8NCg==. Line endings are a classic trap in multi-line values: line1 and line2 joined by \n encode as bGluZTEKbGluZTI=, joined by \r\n as bGluZTENCmxpbmUy. If two systems disagree about a value, compare the byte counts first.

How long the Base64 string will be

Every 3 bytes of input become 4 characters, and a final group of 1 or 2 bytes is padded to 4 with =.

Input bytesBase64 charactersExample (x repeated)
14eA==
24eHg=
34eHh4
48eHh4eA==
1016eHh4eHh4eHh4eA==

So a string grows by about a third, and by more if non-ASCII characters take several bytes each in UTF-8. The Base64 size overhead page has the exact numbers for wrapped output.

Where encoded strings end up

People convert strings to Base64 mostly to move them through places that dislike special characters:

  • Environment variables and CI secrets, where a value with quotes, $ or line breaks would be mangled. postgres://app:s3cret@db:5432/app becomes cG9zdGdyZXM6Ly9hcHA6czNjcmV0QGRiOjU0MzIvYXBw, one line with nothing to escape.
  • Kubernetes Secrets, whose data: values must be Base64. The Kubernetes Secret decoder reads them back.
  • HTTP headers, for example Authorization: Basic with user:password encoded. The Basic Auth header generator builds the full header.
  • JSON and XML fields that must carry arbitrary text without escaping rules getting in the way (JSON to Base64).

None of these hide the value. Anyone with the string can decode it, so treat an encoded secret as a plain secret; see encoding vs encryption.

String to Base64 in code

import base64

base64.b64encode("Grüße".encode("utf-8")).decode("ascii")   # 'R3LDvMOfZQ=='
base64.b64encode("Grüße".encode("cp1252")).decode("ascii")  # 'R3L832U='
// Node.js
Buffer.from("Grüße", "utf8").toString("base64");     // "R3LDvMOfZQ=="
Buffer.from("Grüße", "utf16le").toString("base64");  // "RwByAPwA3wBlAA=="

Both languages need the string-to-bytes step spelled out, which is where the charset choice lives. More on the Python and Node.js pages.

FAQ

How do I convert a string to Base64?

Turn the string into bytes with a charset (UTF-8 almost everywhere), then Base64-encode the bytes. The tool above does both; in Python it is base64.b64encode(s.encode("utf-8")).decode().

Does the same text always give the same Base64?

Only if the bytes are the same. Grüße is R3LDvMOfZQ== in UTF-8 but R3L832U= in Windows-1252, and one extra space or newline changes the result too.

How long will the Base64 string be?

4 × ⌈n / 3⌉ characters for n bytes of input, before any line breaks. A 10-byte string gives 16 characters; the size calculator works it out for any length.

Can I put a Base64 string in a config file or environment variable?

Yes, that is one of its main uses: it turns any value, including line breaks and quotes, into a single line of safe characters. Keep it on one line by leaving Line wrap set to None.