Base64 in Google Sheets
Google Sheets has no built-in BASE64 function, but you can add one in 2 minutes with a tiny Apps Script custom function using Utilities.base64Encode / Utilities.base64Decode. Paste the code below (Extensions → Apps Script), then use =BASE64ENCODE(A1) and =BASE64DECODE(A1) in any cell. Use the tool here to check the expected output.
Is there a BASE64 function in Google Sheets?
No — Google Sheets has no native BASE64ENCODE or BASE64DECODE function. There's no formula for it out of the box. The supported way to get one is to add a custom function with Apps Script, which runs the same Base64 routines Google uses everywhere else (Utilities.base64Encode and Utilities.base64Decode). It takes about two minutes and once saved you call it like any other formula: =BASE64ENCODE(A1). The tool above encodes and decodes the same way in your browser, so you can paste a value and check exactly what a cell should return.
Add BASE64ENCODE / BASE64DECODE custom functions
Open your spreadsheet, go to Extensions → Apps Script, delete any placeholder code, and paste the two functions below. Click Save, then switch back to the sheet — the functions are ready to use immediately, no deploy step required.
function BASE64ENCODE(t) {
return Utilities.base64Encode(t, Utilities.Charset.UTF_8);
}
function BASE64DECODE(s) {
return Utilities.newBlob(Utilities.base64Decode(s)).getDataAsString();
}
Now use them in any cell. If A1 holds Hello:
=BASE64ENCODE(A1) → SGVsbG8=
=BASE64DECODE("SGVsbG8=") → Hello
The Utilities.Charset.UTF_8 argument makes the encoding UTF-8 clean, so accented letters and emoji round-trip correctly. On decode, Utilities.base64Decode returns a byte array, so we wrap it in a Blob and call getDataAsString() to read those bytes back as UTF-8 text.
URL-safe Base64 in Sheets
Need the URL-safe alphabet (- and _ instead of + and /, no = padding)? Apps Script has dedicated web-safe variants. Add these alongside the first pair:
function BASE64ENCODEWEBSAFE(t) {
return Utilities.base64EncodeWebSafe(t, Utilities.Charset.UTF_8);
}
function BASE64DECODEWEBSAFE(s) {
return Utilities.newBlob(Utilities.base64DecodeWebSafe(s)).getDataAsString();
}
Use them exactly like the standard versions: =BASE64ENCODEWEBSAFE(A1). This is the form you want when the Base64 will travel in a URL or a JWT, where +, /, and = would otherwise need escaping.
Convert an image to Base64 in Sheets
You can turn an image URL into a Base64 string with a custom function that fetches the bytes and encodes them. Paste this into the same Apps Script file:
function IMAGEBASE64(url) {
var blob = UrlFetchApp.fetch(url).getBlob();
return Utilities.base64Encode(blob.getBytes());
}
Then call it with the image URL: =IMAGEBASE64("https://example.com/logo.png"). To build a ready-to-use data URI, concatenate the MIME prefix in the sheet: ="data:image/png;base64,"&IMAGEBASE64(A1). Note that a spreadsheet cell holds up to 50,000 characters, so this works well for small icons and logos but will overflow for large photos — encode those with the image-to-Base64 tool instead.
Why not just a formula?
Base64 is a binary-to-text transform, and Sheets' formula language has no primitive for reading raw bytes or doing the base conversion Base64 requires. There's no DEC2BASE64 to pair with DEC2HEX, and stitching one together from CHAR, CODE, and MID would be slow, fragile, and would still mishandle multi-byte UTF-8. Apps Script exists precisely for this: it exposes Google's tested Utilities.base64Encode/Decode routines to your sheet as a one-line custom function. It is the supported, reliable way — cleaner than any formula hack.
Frequently asked questions
Does Google Sheets have a BASE64 formula?
No. There is no built-in BASE64ENCODE or BASE64DECODE function in Sheets. The supported approach is a custom function via Extensions → Apps Script that calls Utilities.base64Encode and Utilities.base64Decode. After saving it, =BASE64ENCODE(A1) and =BASE64DECODE(A1) work like any other formula.
How do I decode Base64 in Google Sheets?
Add the custom function function BASE64DECODE(s){return Utilities.newBlob(Utilities.base64Decode(s)).getDataAsString();}, save it, then use =BASE64DECODE(A1) in a cell. The Base64 tool above shows the expected decoded text so you can confirm the cell matches.
How do I encode an image to Base64 in Sheets?
Use an Apps Script function that fetches the image and encodes its bytes: UrlFetchApp.fetch(url).getBlob() then Utilities.base64Encode(blob.getBytes()). Call it with =IMAGEBASE64("https://example.com/logo.png"). It works best for small images since a cell caps at 50,000 characters.
Is URL-safe Base64 supported?
Yes. Apps Script provides Utilities.base64EncodeWebSafe and Utilities.base64DecodeWebSafe, which use the URL-safe alphabet (- and _). Wrap them in custom functions the same way to get web-safe encode and decode in your cells.
Need plain Base64 encode/decode?
The main base64.dev tool handles text, files, and URL-safe mode with auto-detect.
Open base64.dev →