OnlineTextLab
Esc

What Is Inside a DOCX File? A Zip of XML, and Why That Matters

Updated 7 min read How we check our guides

A DOCX file is a ZIP archive containing XML files, plus any images you inserted. There is nothing proprietary about the container. You can rename a copy to .zip, open it with ordinary software, and read the document’s text in a text editor.

That fact is useful. It lets you pull out images without fuss, rescue text from a file Word refuses to open, and see the author names and deleted text that the file carries around invisibly.

The format is called Office Open XML, standardised as ECMA-376 and ISO/IEC 29500. The same approach is used by .xlsx and .pptx.

Look inside one

You do not need to take our word for this. Here we made a one-page test letter with python-docx, containing a heading, a bold phrase, a table and a photo, and then listed it with unzip -v offer.docx:

 Length   Method    Size  Cmpr    Name
--------  ------  ------- ----    ----
    1789  Defl:N      408  77%    [Content_Types].xml
     734  Defl:N      248  66%    _rels/.rels
     779  Defl:N      411  47%    docProps/core.xml
    1132  Defl:N      491  57%    docProps/app.xml
    3272  Defl:N     1036  68%    word/document.xml
    1359  Defl:N      326  76%    word/_rels/document.xml.rels
  349458  Defl:N    12147  97%    word/styles.xml
  438131  Defl:N    13625  97%    word/stylesWithEffects.xml
    2535  Defl:N      959  62%    word/settings.xml
    2811  Defl:N      611  78%    word/fontTable.xml
   10939  Defl:N     1734  84%    word/theme/theme1.xml
    5513  Defl:N      875  84%    word/numbering.xml
   18687  Defl:N    18542   1%    word/media/image1.jpg
    8324  Defl:N     1469  82%    docProps/thumbnail.jpeg

We trimmed the date and checksum columns and a few small entries for space. Look at the sizes for a moment. The whole letter’s text sits in 3,272 bytes of document.xml, while the styles take up hundreds of kilobytes and compress by 97%. The JPEG barely compresses at all, for the reasons we go into in how ZIP compression works. The finished file came to 55,829 bytes.

To try this on your own file, our ZIP File List accepts .docx directly and runs in your browser. On the command line, the first of these lists the parts, and the second prints the document’s XML:

unzip -v offer.docx
unzip -p offer.docx word/document.xml

On Windows, rename a copy to .zip and double-click it. On a Mac, Archive Utility expands it the same way once renamed.

The parts that matter

PartWhat it holds
[Content_Types].xmlThe type of each part in the package
_rels/.relsThe starting point: which part is the main document
word/document.xmlThe text and its structure
word/styles.xmlNamed styles such as Heading 1
word/numbering.xmlDefinitions for numbered and bulleted lists
word/settings.xmlDocument settings, including whether changes are being tracked
word/_rels/document.xml.relsLinks from the document to images, hyperlinks and other parts
word/media/The original image files
word/header1.xml, footer1.xmlHeaders and footers, when present
word/comments.xmlComments, when present
word/footnotes.xmlFootnotes, when present
docProps/core.xmlTitle, author, last editor, created and modified dates
docProps/app.xmlApplication, page and word counts, template name

How text is stored

The body of document.xml is a sequence of paragraphs (w:p). Each holds one or more runs (w:r), and each run is a stretch of text with the same formatting. Here is the salary sentence from our test letter, indented for reading:

<w:p>
  <w:r><w:t xml:space="preserve">The salary is </w:t></w:r>
  <w:r><w:rPr><w:b/></w:rPr><w:t>fifty thousand</w:t></w:r>
  <w:r><w:t xml:space="preserve"> dollars.</w:t></w:r>
</w:p>

The bold phrase is its own run, with <w:b/> in its properties. Microsoft’s structure overview shows a minimal document in this same pattern.

Runs explain a familiar problem. If you try find-and-replace on the raw XML, a phrase may not match, because Word can split a single word across several runs after spelling checks or edits. Software that edits DOCX has to take this into account.

There is one more thing you will not find, and that is any record of pages. document.xml has no fixed line or page positions. Each program lays out the text when it opens the file, which is the root of the layout shifts we cover in why Word to PDF changes layout.

How images are stored

The original image sits in word/media/ as a normal file. The document holds a reference by ID, which document.xml.rels maps to the file path. The displayed size is a separate instruction (ours was cx="2743200", in units of 1/914,400 of an inch, so 3 inches). So a photo shrunk on the page in Word can still be stored at full size in the file, and this is a common reason a DOCX is huge. Word’s “Compress Pictures” command tackles it.

Why it matters

Getting your images out

Rename a copy to .zip and open word/media/. You get the images as they were inserted, without any screenshot-style quality loss. This is often the quickest way to recover photos from a document someone sent you.

Rescuing a damaged file

If Word reports a file as corrupt, there is often still usable content. Try extracting word/document.xml from the archive. Even if the archive’s ending is damaged, and a repair tool is needed first, the text inside <w:t> tags is there to read. Try Word’s own “Open and Repair” option first, though, since it handles many cases.

Finding what you did not mean to share

This is the reason most people should care. The metadata in our test file read:

<dc:creator>Jane Example</dc:creator>
<cp:lastModifiedBy>Sam Reviewer</cp:lastModifiedBy>
<cp:revision>14</cp:revision>

Real documents carry the real names of whoever typed them, and can show the number of revisions, the organisation and the time spent editing.

Tracked changes are more serious. When a reviewer deletes text with tracking on, Word keeps it in the file. We added a tracked deletion to a copy of our letter using the format Word writes, and the “removed” figure is plainly there in the XML:

<w:del w:id="9" w:author="Sam Reviewer" w:date="2026-03-02T10:15:00Z">
  <w:r><w:delText>sixty thousand</w:delText></w:r>
</w:del>

Switching Word’s view to “No Markup” only hides this, and it stays in the file. Anyone who changes the view, or unzips the file, can read that the earlier figure was sixty thousand, along with who changed it and when. Comments, hidden text and custom XML are stored similarly. So a negotiating position or a colleague’s blunt remark can leave your organisation inside a file that looks clean.

Before sending a DOCX outside your organisation:

  1. Accept or reject all tracked changes, and delete comments.
  2. Run Word’s Document Inspector, which finds comments, revisions, document properties and hidden text. Its documentation notes that it cannot detect text hidden by other methods, such as white text on a white background.
  3. Consider sending a PDF instead, if nobody needs to edit it. See PDF or Word: which to send.

Our DOCX Metadata Viewer gives you a quick look at this without opening Word. On our test file, it showed the creator, last editor and revision number, and counted one tracked deletion and one image. It is a viewer, so it reports these things and does not remove them. Word’s Inspector or a manual clean-up does that.

Not trusting every value

Metadata is only text someone wrote. Our test letter claims a modified date of 2013, and an application name of “Microsoft Macintosh Word”, because python-docx builds on a template file that says so. No version of Word touched it. These values make decent clues, but they do not prove anything on their own.

Processing documents with code

Because it is zip and XML, a script can read a DOCX without Word installed. That is how search indexers, translation tools and converters work. It is how our DOCX to Text tool extracts text, and why tracked deletions (stored as w:delText, not w:t) do not appear in its output. It also leaves things out: on our test letter, the photo did not carry over, since plain text has nowhere to put it.

DOC, DOCM and other relatives

The older .doc format is not a zip of XML. It is a binary format, so none of this applies to it. Word can open one and save it as .docx.

.docm has the same structure as .docx, with the addition of a macro part, word/vbaProject.bin. That part is the code that makes macro-enabled files a security concern. Be careful with unexpected .docm files, and do not enable macros unless you trust the sender and were expecting it. Renaming a .docm to .docx does not turn it into a clean file, and Word will complain about the mismatch rather than open it. For more on what an extension does and does not tell you, see file extensions explained.