How to decode Base64 to XML
- Paste the Base64 into Input · Base64. The page loads with a small sample.
- The XML appears in Output · text. Looks like XML in the status line confirms the content starts like an XML document.
- If the output shows gaps between letters or a binary warning, the XML is UTF-16: set Charset to UTF-16LE, or to Auto-detect if it starts with a byte order mark.
- Copy output copies the text. Download saves the original bytes as
decoded.xml.
The sample PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxub3RlPjx0bz55b3U8L3RvPjxib2R5PkhlbGxvPC9ib2R5Pjwvbm90ZT4= decodes to:
<?xml version="1.0"?>
<note><to>you</to><body>Hello</body></note>
The reverse is XML to Base64.
Recognizing encoded XML
Because XML starts with <, its Base64 starts with P, and the next characters reveal more:
| Base64 starts with | Decoded start | Typical document |
|---|---|---|
PD94bWwg | <?xml | Any XML file with a declaration |
PHNhbWxwOlJlc3BvbnNl | <samlp:Response | SAML login response (SAML decoder) |
PHNvYXA6RW52ZWxvcGU | <soap:Envelope | SOAP message |
PEludm9pY2U | <Invoice | UBL e-invoice |
//48AD8AeABtAGwA | BOM + <?xml in UTF-16LE | XML saved as UTF-16 |
A value that should be SAML but does not start with P is usually compressed XML; how to inflate it is explained below.
UTF-16 and other encodings
Most XML is UTF-8, which the decoder assumes. Two cases need a different Charset:
- UTF-16 documents, common from Windows tools and .NET, have a zero byte next to every ASCII character. Decoded as UTF-8 they look like binary data, and the tool says so. With Auto-detect or UTF-16LE the full text appears, starting with
<?xml version="1.0" encoding="UTF-16"?>. Download keeps the bytes but names the filedecoded.bin, so rename it to.xml. - Latin-1 or Windows-1252 documents declare
encoding="ISO-8859-1"or similar. Accented letters show as�in UTF-8 mode; pick the declared charset to read them.
The XML declaration inside the output tells you which charset the author intended. An XML parser reading the downloaded file uses that declaration, so the file is fine even if the on-screen preview needed a manual charset choice.
Where Base64 XML comes from
SAML is the most frequent source: identity providers post the SAMLResponse to your application as Base64-encoded XML, and copying it from the browser’s network tab is the usual way to debug a login. SOAP services and e-invoicing platforms return documents and attachments as Base64 fields. Email can carry XML attachments as MIME Base64 parts, which the email decoder extracts.
For SAML SAMLRequest values from redirect URLs, the XML was compressed with raw DEFLATE before encoding, so plain Base64 decoding yields binary. The gzip Base64 decoder inflates it. The escapes %2B, %2F and %3D are decoded automatically; for a fully URL-encoded value, use the URL decoder first.
Base64 to XML in code
Pass the decoded bytes to the XML parser without turning them into a string first, so it reads the encoding from the declaration itself:
import base64
import xml.etree.ElementTree as ET
s = "PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxub3RlPjx0bz55b3U8L3RvPjxib2R5PkhlbGxvPC9ib2R5Pjwvbm90ZT4="
root = ET.fromstring(base64.b64decode(s))
root.find("body").text # 'Hello'
// Browser
const s = "PD94bWwgdmVyc2lvbj0iMS4wIj8+Cjxub3RlPjx0bz55b3U8L3RvPjxib2R5PkhlbGxvPC9ib2R5Pjwvbm90ZT4=";
const bytes = Uint8Array.from(atob(s), c => c.charCodeAt(0));
const doc = new DOMParser().parseFromString(new TextDecoder().decode(bytes), "application/xml");
For UTF-16 or Latin-1 XML in the browser, pass the right label to TextDecoder. More in Base64 in Python and Base64 in JavaScript.
FAQ
How do I decode Base64 to an XML file?
Paste the Base64 above. When the status line says XML, Download saves the decoded bytes as decoded.xml, byte for byte, with the original encoding and any signature intact.
How can I tell if Base64 contains XML?
Documents with an XML declaration start with PD94bWwg (<?xml ). Without a declaration the string still starts with P, because every document starts with <; PHNhbWxwOlJlc3BvbnNl is <samlp:Response.
Can the tool format or indent the XML?
No. XML is shown exactly as decoded; the Pretty-print JSON option applies to JSON only. Showing the original bytes matters for signed XML, where any reformatting changes the content.
Why does my decoded SAML request look like random bytes?
SAML requests sent in a redirect URL are compressed with raw DEFLATE before Base64 encoding. Inflate them with the gzip Base64 decoder or open them in the SAML decoder.