Upload a file
  1. base64hub
  2. File tools
  3. Word to Base64

Word to Base64

Drop a .docx or .doc file and copy its Base64 for a JSON field or an email attachment. Contracts and drafts stay on your computer; the page cannot send them anywhere.

Free no sign-up, no limits Local nothing uploaded Updated Oct 27, 2026
Drop files here, paste, or pick them
Input –Output –Size –

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

How to convert a Word document to Base64

  1. Drop a .docx or .doc file on the box or choose it with the file picker. Several files at once are fine.
  2. Output as starts on Plain Base64. JSON wraps it with the file name, MIME type and size; HTML <a download> makes a download link.
  3. Tick Wrap at 76 only for a hand-built MIME email.
  4. Copy output.

Save the document before encoding it. The tool reads the file as it is on disk, so edits still open in Word are not included.

DOCX or DOC: check the first characters

FileWhat it isBase64 starts with
.docxZIP container with XML partsUEsDB
.docm (with macros)same ZIP containerUEsDB
.docCompound File Binary (OLE2)0M8R4KGxGuE
encrypted .docxencrypted package in a compound file0M8R4KGxGuE

If a service rejects your “DOCX” as invalid and the Base64 starts with 0M8R4KGxGuE, you are sending either an old .doc renamed to .docx or a password-protected file. If it starts with JVBERi0, someone saved a PDF with a .docx name. PCFET0NUWVBF or PGh0bWw means HTML, often a download that returned an error page.

Where Base64 Word files go

  • E-signature and document-generation APIs take the document as Base64 in a JSON body, together with a file name and MIME type, and often return a filled or signed document the same way.
  • Transactional email APIs accept attachments as Base64 strings in JSON. The raw MIME version of the same thing uses 76-character lines; see Base64 in email.
  • Conversion services that turn DOCX into PDF accept the source file inline when it is small.

Base64 is a transport format and protects nothing: anyone who intercepts the string can decode the document with Base64 to Word. For confidential files, rely on TLS and access control, or encrypt the document. See encoding vs encryption.

Encode a DOCX in PHP

<?php
$path = 'contract.docx';
$payload = json_encode([
    'filename' => basename($path),
    'contentType' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
    'content' => base64_encode(file_get_contents($path)),
], JSON_UNESCAPED_SLASHES);

Without JSON_UNESCAPED_SLASHES, PHP writes every / in the Base64 as \/. That is valid JSON and decodes correctly, but it makes the string longer and breaks naive text comparisons. The key names are placeholders for whatever your API uses. More in Base64 in PHP.

For Excel files the same approach applies, with a different MIME type; see Excel to Base64. If the receiver can take PDF, PDF to Base64 avoids layout differences between Word versions.

FAQ

What MIME type goes with a Base64 DOCX?

application/vnd.openxmlformats-officedocument.wordprocessingml.document. The older .doc format is application/msword. APIs often need the type in a separate field, and some use it to pick a converter.

Why does my DOCX Base64 start with UEsDB?

A DOCX is a ZIP archive of XML files, and every ZIP starts with PK\x03\x04, which is UEsDB in Base64. An old binary .doc starts with 0M8R4KGxGuE instead.

My password-protected DOCX starts with 0M8R4KGxGuE. Is it broken?

No. When Word encrypts a DOCX, it stores the encrypted package inside the older compound-file container, so it gets the .doc-style header. The file is fine; the receiver needs the password to open it.