XML to Base64 converter
Paste XML and get Base64 instantly, as one continuous string or split into lines, with a URL-safe option. Switch direction to decode Base64 back into readable, indented XML. Everything runs in your browser.
every 3 bytes of XML = 4 Base64 characters
PHNldHRpbmdzPgogIDxmZWF0dXJlIG5hbWU9InNlYXJjaCIgZW5hYmxlZD0idHJ1ZSIvPgogIDxsaW1pdD4yNTwvbGltaXQ+Cjwvc2V0dGluZ3M+
Encoded · 84 bytes → 112 characters
Everything runs in your browser; nothing is uploaded.
How to convert XML to Base64
- Paste your XML into the box above. The tool checks it as you type and tells you if a tag is not closed.
- Pick the output: One line for JSON, APIs and config values; 64 per line or 76 per line if the receiving system expects line breaks, as email and many SOAP tools do.
- Choose URL-safe if the Base64 is going into a URL or a file name.
- Copy the result. To check it, switch to Base64 → XML and the original comes back.
Behind the scenes the XML is turned into UTF-8 bytes, and every 3 bytes become 4 Base64 characters. Tags, attributes and indentation are encoded exactly as written, so decoding always gives back the identical text.
Worked example: <root><item>Hello</item></root>
This small document is 31 characters, and each one is a single byte in UTF-8.
Step 1: Split the bytes into groups of three
Step 2: Each group of 3 bytes becomes 4 characters
Step 3: Pad the last group with =
Result: PHJvb3Q+PGl0ZW0+SGVsbG88L2l0ZW0+PC9yb290Pg==. That is 44 characters for 31 bytes. With URL-safe on, each + becomes - and the == is dropped: PHJvb3Q-PGl0ZW0-SGVsbG88L2l0ZW0-PC9yb290Pg.
XML to Base64 in Python, JavaScript, C#, Java and the command line
In every language the pattern is the same: turn the XML into UTF-8 bytes, then Base64-encode the bytes.
# Python
import base64
xml_data = "<root><item>Hello</item></root>"
encoded = base64.b64encode(xml_data.encode("utf-8")).decode("utf-8")
// JavaScript (Node.js)
const encoded = Buffer.from(xmlData, "utf8").toString("base64");
// JavaScript (browser)
const encoded = btoa(String.fromCharCode(...new TextEncoder().encode(xmlData)));
// C#
string encoded = Convert.ToBase64String(Encoding.UTF8.GetBytes(xmlData));
// Java
String encoded = Base64.getEncoder().encodeToString(xmlData.getBytes(StandardCharsets.UTF_8));To encode a whole file from the command line:
base64 -w 0 data.xml # Linux
base64 -i data.xml # macOS
[Convert]::ToBase64String([IO.File]::ReadAllBytes("$PWD\data.xml")) # Windows PowerShellIn the browser, btoa(xmlData) on its own throws an error as soon as the XML contains é, € or any other character beyond basic Latin, which is why the line above encodes to UTF-8 first. You may also see btoa(unescape(encodeURIComponent(xmlData))); it gives the same result, but unescape is deprecated.
Base64 to XML: decoding it back
Switch the tool to Base64 → XML and paste the Base64. The decoded XML is indented so it is easy to read; turn off Format XML to see it exactly as it was encoded. The status line shows the root element and whether the XML is well-formed.
Line breaks, spaces and a data:application/xml;base64, prefix are ignored, and URL-safe Base64 works too. If you paste a single sign-on (SAML) message, the tool also undoes the URL encoding and compression those messages use. In code:
base64.b64decode(encoded).decode("utf-8") # Python
Buffer.from(encoded, "base64").toString("utf8") // Node.js
Encoding.UTF8.GetString(Convert.FromBase64String(s)) // C#If the result is “not UTF-8 text”, the Base64 holds something other than plain XML: usually a compressed or encrypted file, or XML saved in another encoding such as UTF-16.
Why encode XML as Base64?
Base64 turns XML into plain letters and digits with no <, quotes or line breaks, so it can travel inside something else without being misread or reformatted:
- JSON and REST APIs: an XML document sent as one string field, without escaping every quote.
- Email and SOAP attachments: XML files attached to a message, usually split into 76-character lines.
- Config files and environment variables: a whole XML file stored as a single value.
- Single sign-on: SAML login messages are XML, Base64-encoded between the identity provider and your app.
- Databases and logs: XML kept in a text column or log line without breaking the format around it.
Frequently asked questions
Is Base64 encryption?
No. Anyone can decode Base64 instantly, so it hides nothing. It only changes how the XML is written so it can travel safely. Use encryption if the XML contains anything private.
How much bigger is XML in Base64?
About a third. Every 3 bytes become 4 characters, plus up to two = at the end, so a 3 KB XML file becomes 4 KB of Base64. Line breaks add a little more.
Should I use one line or line breaks?
One line, unless the system receiving it asks for line breaks. JSON, APIs and most code expect a continuous string. Email (MIME) uses 76 characters per line, and PEM-style files use 64.
How can I tell if Base64 is XML?
XML starts with <, which becomes P at the start of Base64. PD94bWwg is "<?xml ", and PG or PH is usually an opening tag such as <root> or <settings>. Paste it into the decoder to be sure.
Sources
- RFC 4648: The Base16, Base32, and Base64 Data Encodings: the standard and URL-safe alphabets, and padding
- Python docs: base64: b64encode() and b64decode()
- MDN: btoa(): why non-Latin-1 text must be encoded to UTF-8 first
- Microsoft Learn: Convert.ToBase64String: Base64 in C#
- Java SE: java.util.Base64: Base64 in Java
Related Tools
Build and preview Valorant crosshair settings.
Search common Vim commands.
Turn JSON rows into bar, line, or pie charts.
Convert WebP files and Base64 data in both directions.
Convert GIF files and Base64 data in both directions.
Save any GIF frame, or all frames, as JPG.