AMPscript Base64Decode (Next)
Decode a Base64 string with AMPscript Base64Decode in Marketing Cloud Next. Syntax, examples, and behaviour proven in a Marketing Cloud Next email, including the missing-padding case where Next and Engagement part ways.
Syntax
Base64Decode(encodedString[, encoding, abortOnFailure]) → string
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
encodedString |
string | Yes | Base64 to decode; a value missing its = padding is still decoded, other malformed input makes the render fail |
encoding |
string | No | Name of the character encoding the decoded bytes are read as; defaults to UTF-8 |
abortOnFailure |
string | boolean | number | No | Truthy makes the render fail when the value cannot be decoded, falsy returns an empty string instead; only a failed decode is affected. Accepts true, false, 1, 0, "true", "false", "1", "0" |
Example
%%=Base64Decode("U0ZNQyBBTVBzY3JpcHQgMjAyNg==")=%%
Renders SFMC AMPscript 2026.
Paired with Base64Encode, the value comes back unchanged:
%%=Base64Decode(Base64Encode("SFMC AMPscript 2026"))=%%
Renders SFMC AMPscript 2026.
Return value
string — the decoded text, read from the decoded bytes in the requested encoding.
There is no error token to test for: a value that cannot be decoded either makes the render fail or, with a falsy third argument, returns an empty string.
Behaviour
Standard Base64 decodes as expected. Base64Decode("SGVsbG8=") gives Hello, and the empty string gives the empty string.
The round trip is exact, non-ASCII included. Base64Decode(Base64Encode("café€")) returns café€.
The bytes are read as UTF-8 unless you name another encoding. Passing "UTF-8" explicitly gives the same result as leaving it out. A payload that holds UTF-16 bytes decodes correctly with "UTF-16"; without it, the output carries a NUL character after every letter.
The third argument only matters when decoding fails. All eight literals true, false, 1, 0, "true", "false", "1" and "0" are accepted, and a valid value decodes to the same text whichever one you pass. For malformed input, Base64Decode("not!base64###", "UTF-8", 0) returns an empty string, while the same call with 1 makes the render fail.
Missing padding is tolerated. Base64Decode("SGVsbG8"), the Base64 of Hello without its trailing =, renders Hello.
Other malformed input breaks the render. An email containing Base64Decode("not!base64###") or Base64Decode("SGVsbG8=====") saves, but its preview fails. Check values from outside sources before decoding them, or pass a falsy third argument.
Wrong argument counts are refused at save. An email with Base64Decode() or with four arguments cannot be saved: the content API answers HTTP 400 with “The AMPscript syntax isn’t valid”.
Show Next test script
<!-- Marketing Cloud Next test script for Base64Decode. Paste it into the HTML component of a
Next email and open the preview. Each line prints the result Next gave when the call
was rendered on its own (expect) next to the result of this run (got).
Assembled from single-call test emails (dates on the page); it has not been
run as one email. Calls that make Next fail are listed separately. -->
<p>c1 expect=[Hello] got=[%%=Base64Decode("SGVsbG8=")=%%]</p>
<p>c2 expect=[SFMC AMPscript 2026] got=[%%=Base64Decode("U0ZNQyBBTVBzY3JpcHQgMjAyNg==")=%%]</p>
<p>c3 expect=[] got=[%%=Base64Decode("")=%%]</p>
<p>c4 expect=[SFMC AMPscript 2026] got=[%%=Base64Decode(Base64Encode("SFMC AMPscript 2026"))=%%]</p>
<p>c5 expect=[café€|café€] got=[%%=Concat("café€","|",Base64Decode(Base64Encode("café€")))=%%]</p>
<p>c6 expect=[SFMC AMPscript 2026] got=[%%=Base64Decode("U0ZNQyBBTVBzY3JpcHQgMjAyNg==","UTF-8")=%%]</p>
<p>c7 expect=[SFMC AMPscript 2026] got=[%%=Base64Decode("UwBGAE0AQwAgAEEATQBQAHMAYwByAGkAcAB0ACAAMgAwADIANgA=","UTF-16")=%%]</p>
<p>c8 expect=[SU+0000FU+0000MU+0000CU+0000 U+0000AU+0000MU+0000PU+0000sU+0000cU+0000rU+0000iU+0000pU+0000tU+0000 U+00002U+00000U+00002U+00006U+0000] got=[%%=Base64Decode("UwBGAE0AQwAgAEEATQBQAHMAYwByAGkAcAB0ACAAMgAwADIANgA=")=%%]</p>
<p>c9 expect=[SFMC AMPscript 2026] got=[%%=Base64Decode("U0ZNQyBBTVBzY3JpcHQgMjAyNg==","UTF-8",1)=%%]</p>
<p>c10 expect=[SFMC AMPscript 2026] got=[%%=Base64Decode("U0ZNQyBBTVBzY3JpcHQgMjAyNg==","UTF-8",0)=%%]</p>
<p>c11 expect=[SFMC AMPscript 2026] got=[%%=Base64Decode("U0ZNQyBBTVBzY3JpcHQgMjAyNg==","UTF-8",true)=%%]</p>
<p>c12 expect=[SFMC AMPscript 2026] got=[%%=Base64Decode("U0ZNQyBBTVBzY3JpcHQgMjAyNg==","UTF-8",false)=%%]</p>
<p>c13 expect=[SFMC AMPscript 2026] got=[%%=Base64Decode("U0ZNQyBBTVBzY3JpcHQgMjAyNg==","UTF-8","1")=%%]</p>
<p>c14 expect=[SFMC AMPscript 2026] got=[%%=Base64Decode("U0ZNQyBBTVBzY3JpcHQgMjAyNg==","UTF-8","0")=%%]</p>
<p>c15 expect=[SFMC AMPscript 2026] got=[%%=Base64Decode("U0ZNQyBBTVBzY3JpcHQgMjAyNg==","UTF-8","true")=%%]</p>
<p>c16 expect=[SFMC AMPscript 2026] got=[%%=Base64Decode("U0ZNQyBBTVBzY3JpcHQgMjAyNg==","UTF-8","false")=%%]</p>
<p>c17 expect=[] got=[%%=Base64Decode("not!base64###","UTF-8",0)=%%]</p>
<p>c18 expect=[Hello] got=[%%=Base64Decode("SGVsbG8")=%%]</p>
Show calls that fail in Next (one email each)
<!-- Run each call below in its own Next email: one of them in a combined email
would stop the whole preview or block the save. -->
<!-- email 1: expect that the email saves, but the preview never shows the new version (no fresh render) -->
%%=Base64Decode("not!base64###")=%%
<!-- email 2: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Base64Decode("SGVsbG8=====")=%%
<!-- email 3: expect that the save is rejected (HTTP 400) -->
%%=Base64Decode()=%%
<!-- email 4: expect that the save is rejected (HTTP 400) -->
%%=Base64Decode("U0ZNQyBBTVBzY3JpcHQgMjAyNg==","UTF-8",1,"extra")=%%
<!-- email 5: expect that the email saves, but the preview fails (HTTP 500) -->
%%=Base64Decode("not!base64###","UTF-8",1)=%%
Availability & differences
| Platform | Available |
|---|---|
| Marketing Cloud Engagement | Yes |
| Marketing Cloud Next | Yes, from API 68.0 |
Engagement aborts the page with HTTP 422 for Base64Decode("SGVsbG8"), a value that only lacks its = padding; Next decodes it to Hello. Well-formed input, the UTF-16 encoding, the abort flag and other malformed values such as not!base64### behave alike on both. Compared 2026-11-23 by rendering the same calls in a Marketing Cloud Next email.
See also
- Base64Encode — the inverse
- StringToHex — the same bytes as hexadecimal
- Official reference