What's Actually Inside a .docx File

Rename any .docx to .zip and open it. Inside is a small filesystem of XML documents, images and relationship files. Understanding that structure turns a Word document from an opaque blob into something you can inspect, repair, generate programmatically and audit for information you did not mean to send.

The structure

A .docx is a ZIP archive following the Office Open XML specification. word/document.xml holds the text, word/media/ holds every image at full resolution, docProps/ holds metadata, and _rels/ files describe how the pieces connect.

The archive layout

document.docx โ”œโ”€โ”€ [Content_Types].xml โ† declares the MIME type of every part โ”œโ”€โ”€ _rels/ โ”‚ โ””โ”€โ”€ .rels โ† package-level relationships โ”œโ”€โ”€ docProps/ โ”‚ โ”œโ”€โ”€ core.xml โ† author, dates, revision count โ”‚ โ”œโ”€โ”€ app.xml โ† editing time, word count, application โ”‚ โ””โ”€โ”€ thumbnail.jpeg โ† optional preview โ””โ”€โ”€ word/ โ”œโ”€โ”€ document.xml โ† THE TEXT โ”œโ”€โ”€ styles.xml โ† style definitions โ”œโ”€โ”€ settings.xml โ† document settings โ”œโ”€โ”€ fontTable.xml โ† fonts referenced โ”œโ”€โ”€ numbering.xml โ† list definitions โ”œโ”€โ”€ theme/theme1.xml โ† colours and fonts โ”œโ”€โ”€ media/ โ† EVERY IMAGE, full size โ”‚ โ”œโ”€โ”€ image1.png โ”‚ โ””โ”€โ”€ image2.jpeg โ”œโ”€โ”€ comments.xml โ† if comments exist โ”œโ”€โ”€ footnotes.xml โ”œโ”€โ”€ header1.xml โ””โ”€โ”€ _rels/ โ””โ”€โ”€ document.xml.rels โ† what document.xml points at
# Look inside without extracting unzip -l document.docx # Extract everything unzip document.docx -d unpacked/ # Read the main document readably unzip -p document.docx word/document.xml | xmllint --format -

The relationship system

OOXML never references another part by path. It uses a relationship ID resolved through a _rels file:

<!-- word/_rels/document.xml.rels --> <Relationship Id="rId7" Type=".../image" Target="media/image1.png"/> <!-- word/document.xml refers to the ID, not the path --> <a:blip r:embed="rId7"/>

The indirection buys real things. A part can be renamed or moved without touching every reference to it. External links โ€” a hyperlink to a website โ€” use the same mechanism as internal ones, so a consumer handles both identically. And a security boundary exists: an application can inspect every external target in one place before deciding whether to follow any of them.

โš ๏ธ Editing by hand means editing two files

Adding an image is not one operation. You must add the file to word/media/, add a <Relationship> entry with a new unique ID, reference that ID in document.xml, and ensure [Content_Types].xml declares the image's extension. Miss any one and Word reports the document as corrupt.

Inside document.xml

<w:document> <w:body> <w:p> โ† paragraph <w:pPr> โ† paragraph properties <w:pStyle w:val="Heading1"/> </w:pPr> <w:r> โ† run โ€” a span of uniform formatting <w:rPr><w:b/></w:rPr> โ† run properties: bold <w:t>Hello</w:t> โ† the actual text </w:r> <w:r> <w:t xml:space="preserve"> world</w:t> </w:r> </w:p> <w:sectPr>โ€ฆ</w:sectPr> โ† page size, margins </w:body> </w:document>
ElementMeans
w:pParagraph
w:rRun โ€” a span sharing identical formatting
w:tText
w:pPr / w:rPrParagraph / run properties
w:tbl, w:tr, w:tcTable, row, cell
w:brLine or page break
w:ins / w:delTracked insertion / deletion
w:commentRangeStartComment anchor

๐Ÿšจ The run-splitting problem

Word splits text into a new run at every change of formatting โ€” and also at changes in spell-check state, language tagging, revision marks and proofing status. The result is that a visually continuous sentence is frequently spread across several runs:

<!-- "confidential salary data" as Word may store it --> <w:r><w:t>confid</w:t></w:r> <w:r><w:rPr><w:lang w:val="en-US"/></w:rPr><w:t>ential </w:t></w:r> <w:r><w:t>salary data</w:t></w:r>

A search-and-replace over the raw XML for "confidential" finds nothing. Any tool that redacts or substitutes text must normalise runs first โ€” merge adjacent runs with identical properties โ€” or it will silently miss matches. This is a well-known source of failed redaction in automated document processing.

What the document is carrying

<!-- docProps/core.xml --> <dc:creator>Jane Smith</dc:creator> <cp:lastModifiedBy>Robert Chen</cp:lastModifiedBy> <dcterms:created>2026-03-14T09:22:00Z</dcterms:created> <dcterms:modified>2026-08-01T16:45:00Z</dcterms:modified> <cp:revision>47</cp:revision> <!-- docProps/app.xml --> <TotalTime>1840</TotalTime> โ† minutes spent editing <Company>Acme Corporation</Company> <Application>Microsoft Office Word</Application>

That is a meaningful amount of information to attach to a document sent outside an organisation: who wrote it, who last touched it, when it started, how many revisions it went through, and how many hours were spent on it.

What persistsWhere
Author and last editordocProps/core.xml
Total editing time, companydocProps/app.xml
Tracked changes with author namesword/document.xml
Comments and their authorsword/comments.xml
Full-resolution imagesword/media/
Text that was cropped from an imageword/media/ โ€” see below
Earlier versions of edited textword/document.xml if changes are tracked

๐Ÿšจ Word crops are only a display setting

Cropping an image in Word does not modify the image. It records a display rectangle and stores the complete original in word/media/. Anyone who opens the archive sees everything that was cropped away.

The same applies to a black rectangle drawn over text to redact it โ€” the shape sits above the text and the text remains in document.xml, fully selectable. This has caused a long series of real disclosures in legal and government documents.

To actually remove content: crop in an image editor before inserting, delete the text rather than covering it, and run Document Inspector (File โ†’ Info โ†’ Check for Issues) before sending anything sensitive.

Recovering a corrupt document

This is one of the most useful practical consequences of the ZIP structure. When Word declares a file unrepairable, usually only one part is damaged โ€” the rest is intact and readable.

# 1. Work on a copy, always cp broken.docx recovery.zip # 2. See what is intact unzip -t recovery.zip # 3. Extract whatever will extract unzip -o recovery.zip -d recovered/ # 4. Every image is already usable ls recovered/word/media/ # 5. Pull the text out of the XML xmllint --format recovered/word/document.xml | \ sed -e 's/<[^>]*>/ /g' | tr -s ' '

If document.xml itself is damaged, an XML parser will report the exact line and column of the failure โ€” frequently a truncated tag at the very end, which can be closed by hand. Repairing the last few characters of a 200,000-character file often restores the whole document.

Generating documents programmatically

Because the format is a documented ZIP of XML, producing Word documents from code needs no Word installation.

LanguageLibrary
Pythonpython-docx, docxtpl
JavaScriptdocx, docxtemplater
JavaApache POI
C#Open XML SDK
PHPPhpWord

โœ… Template, do not construct

Building a document element by element produces valid XML and usually ugly output โ€” matching a designed template's styles, spacing and headers from code is a great deal of work.

The reliable approach is to have someone design the document in Word with placeholders, then substitute values into a copy. The formatting is already correct because a person made it correct, and the code only handles data.

One caveat, and it is the run-splitting problem again: a placeholder like {{name}} may be split across runs by Word's proofing state. Template libraries handle this by normalising runs first โ€” which is exactly why writing your own substitution with a regular expression fails intermittently and confusingly.

The same structure elsewhere

FormatMain content fileNotable
.xlsxxl/worksheets/sheet1.xmlText lives in xl/sharedStrings.xml, referenced by index
.pptxppt/slides/slide1.xmlOne file per slide, plus layouts and masters
.odtcontent.xmlOpenDocument โ€” flatter, arguably cleaner
.epubOEBPS/content.opfChapters are ordinary HTML files

The sharedStrings.xml design in Excel is worth noting: every distinct string in the workbook is stored once, and cells reference it by index. A spreadsheet with a hundred thousand rows of repeated category names stores each name once. It is a small piece of deduplication that makes a large difference on real data.

Working with document formats?

Convert between Markdown, HTML and other formats, or merge and split PDFs โ€” all in your browser, nothing uploaded.

Open the Markdown Converter โ†’

Summary

  • A .docx is a ZIP of XML. Rename a copy and open it.
  • Parts reference each other by relationship ID, resolved through _rels files.
  • Text is split into runs at every formatting and proofing boundary, which breaks naive search and replace.
  • Images are stored at full resolution regardless of displayed size โ€” usually the reason a document is large.
  • Word crops and black boxes hide nothing. The original data is in the archive.
  • Metadata includes author, editor, revision count and editing time. Run Document Inspector before sending.
  • Corrupt documents are frequently recoverable by extracting the archive directly.
  • Template rather than construct when generating documents from code.

Frequently Asked Questions

Is a .docx file really a ZIP archive?

Yes. Rename a copy to .zip and any archiver will open it. Inside you will find XML files describing the text and formatting, a media folder containing every image at full resolution, and property files holding metadata. The same is true of .xlsx, .pptx, .odt and .epub.

How do I recover text from a corrupt Word document?

Rename a copy to .zip, open it, and read word/document.xml in a text editor โ€” the text is there among the tags. Every image is in word/media/ as an ordinary file. This frequently recovers content from documents Word itself declares unrepairable, because only one part of the archive is usually damaged.

Why does searching document.xml for a phrase often fail?

Because Word splits text into runs at every formatting boundary, and also at points where spell-check state, language tagging or revision marks change. A sentence that looks continuous can be split across several run elements with tags between the words, so a plain text search for the whole phrase finds nothing.

What metadata does a Word document contain?

docProps/core.xml holds the author, last modified by, creation and modification times and revision count. docProps/app.xml adds the total editing time, word and page counts, the application version and often a company name. Tracked changes and comments persist in document.xml until explicitly removed.

Why is my Word document so large?

Almost always images. Word stores pasted pictures in word/media/ at full resolution regardless of the size they are displayed at, so a screenshot scaled down on the page still occupies its original bytes. Open the archive and check the folder โ€” it is usually the overwhelming majority of the file.

P

Written by Paras

We build free, browser-based file tools and write the reference material we wish existed when we were looking things up. Spotted an error? Tell us and we will fix it.