Inside a DOCX File: Signature, Structure and MIME Type
Learn how DOCX is identified and what its internal components mean.
Inside a DOCX File: Signature, Structure and MIME Type
The ZIP Foundation
A DOCX file is a ZIP archive containing a structured collection of XML parts, not a monolithic binary format. The Office Open XML (OOXML) standard, formalized as ISO/IEC 29500 and profiled by Microsoft in the MS-DOCX reference, defines this packaging. Any ZIP-compatible tool can extract a DOCX, but only an OOXML processor interprets the relationships and content types that give the parts meaning.
A critical constraint follows from this architecture: if the ZIP structure is damaged, the document is unrecoverable regardless of the XML quality inside. The central directory at the end of the archive is the index required to locate all entries; without it, individual parts cannot be reliably found.
File Signature: The First Four Bytes
The file signature for a DOCX is the ZIP local file header magic number: 50 4B 03 04 (ASCII PK followed by two control bytes). Every .zip, .odt, .pptx, and .xlsx file shares this identical header. The signature alone cannot distinguish a DOCX from other ZIP-based formats.
| Offset (bytes) | Hex Value | Meaning |
|---|---|---|
| 0–3 | 50 4B 03 04 |
Local file header signature |
| 4–5 | 0A 00 or 2D 00 |
Minimum version needed to extract (2.0 or 4.5) |
| 6–7 | 00 00 or 08 08 |
General purpose bit flag (bit 3 set = data descriptor follows) |
Validation check: Run xxd -l 8 document.docx on Linux or Format-Hex -Count 8 document.docx in PowerShell. If bytes 0–3 are not 50 4B 03 04, the file is not a valid ZIP archive—it may be a renamed legacy .doc (OLE2 compound file, signature D0 CF 11 E0) or a truncated download.
Internal Structure: Three Mandatory Parts
A minimal valid DOCX must contain exactly these three entries inside the ZIP, as required by the Open Packaging Conventions referenced in the MS-DOCX specification:
[Content_Types].xml— Maps every part extension and specific paths to MIME types. Without this file, a processor cannot determine which parts contain document content versus images or metadata._rels/.rels— The root relationships part. It declares the starting point for the document package (typicallyword/document.xml) and links to shared resources such as styles or footnotes.word/document.xml— The main document body. All paragraph text, runs, formatting properties, and inline objects reside here. Binary resources like images are stored separately underword/media/.
A minimal DOCX can contain as few as four files total (the three above plus word/_rels/document.xml.rels). The presence of word/document.xml inside a ZIP archive is the most reliable single indicator that a file is a DOCX rather than another OOXML format.
MIME Type Registration and Detection
The IANA-registered MIME type for DOCX is:
application/vnd.openxmlformats-officedocument.wordprocessingml.document
Detection operates at two levels:
- Extension-based: The
.docxsuffix maps directly to the MIME type. This is the fastest method but fails when extensions are renamed or missing. - Content sniffing: Extract
[Content_Types].xmlfrom the ZIP and locate theOverrideelement for/word/document.xml. TheContentTypeattribute must equalapplication/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml. This is the method used by Apache Tika,libmagic, and LibreOffice.
Content sniffing is definitive but requires partial ZIP decompression. For batch processing, validate the ZIP signature first (4 bytes), then parse content types only when the signature matches.
The [Content_Types].xml Override Mechanism
The content types part uses a flat XML structure with two element types:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">
<Default Extension="rels"
ContentType="application/vnd.openxmlformats-package.relationships+xml"/>
<Default Extension="xml" ContentType="application/xml"/>
<Default Extension="png" ContentType="image/png"/>
<Override PartName="/word/document.xml"
ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml"/>
</Types>
Defaultelements assign a MIME type to all parts with a given extension. Unlisted extensions are treated asapplication/octet-stream.Overrideelements assign a specific MIME type to a single named path, taking precedence over anyDefaultmatch.
The Override for /word/document.xml is what definitively marks the archive as a DOCX. If this override is absent or points to a different content type, processors must reject the file. A missing or malformed [Content_Types].xml produces a "file is damaged" error even when word/document.xml is well-formed.
The Relationships Part: Connecting the Pieces
_rels/.rels uses the OPC Relationships schema:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId1"
Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument"
Target="word/document.xml"/>
</Relationships>
Each Relationship element carries three attributes:
| Attribute | Constraint | Purpose |
|---|---|---|
Id |
Unique within the file, rId prefix convention |
Referenced from document XML to resolve linked resources |
Type |
Absolute URI from the OPC or OOXML namespace | Identifies the semantic role (officeDocument, styles, image) |
Target |
Relative URI, must exist in the ZIP | Path to the target part |
The officeDocument relationship type is the single entry point. Additional relationships to word/styles.xml, word/footnotes.xml, or word/media/image1.png are optional but present in any document with formatting beyond plain text. A relationship with a Target that does not resolve to an existing ZIP entry produces a broken reference error at load time.
Hard Limits and Validation Checks
The OOXML specification and ZIP format impose measurable constraints:
- ZIP entry count: A ZIP archive can contain up to 65,535 entries (16-bit field in the central directory). DOCX files with embedded fonts and high-resolution media can approach this limit.
- Part name length: Part names (paths inside the ZIP) must not exceed 256 UTF-16 code units.
- XML size: No single XML part may exceed 2 GB uncompressed. In practice,
word/document.xmlfor a large document can reach hundreds of megabytes. - Relationships count: No explicit upper bound, but each relationship requires a unique
Idattribute; processors may impose practical limits on ID resolution.
Observable validation sequence for an unknown file:
- Read bytes 0–3. Reject if not
50 4B 03 04. - Locate the ZIP end-of-central-directory record (signature
50 4B 05 06at variable offset from EOF). Reject if missing. - Parse the central directory and confirm
[Content_Types].xmlandword/document.xmlare present. - Extract and parse
[Content_Types].xml. Confirm theOverridefor/word/document.xmlcarries the DOCX main document content type. - Parse
_rels/.relsand verify theofficeDocumentrelationshipTargetresolves to an existing part.
Failure Modes by Layer
Corruption manifests differently depending on which structural layer is damaged:
| Damage Location | Observable Symptom | Recovery Potential |
|---|---|---|
| ZIP local header (bytes 0–3) | "Not a valid archive" or format not recognized | Unrecoverable without raw ZIP repair |
[Content_Types].xml missing or invalid |
"File is damaged" or "Unknown format" | Reconstructable if the internal structure is known |
word/document.xml malformed |
"Could not read content" or partial rendering | XML repair possible up to the first fatal parse error |
| ZIP central directory truncated | "Unexpected end of archive" | Recoverable with zip -F or equivalent stream reconstruction |
Relationship Target broken |
"Part not found" for a specific resource | Missing resource skipped; document may open with degraded content |
The most common real-world failure is a truncated central directory caused by interrupted downloads or incomplete file transfers. ZIP repair tools can scan for local file headers and rebuild the directory, recovering all parts that are fully intact.
Distinguishing DOCX from Other OOXML Formats
DOCX shares its ZIP packaging with PPTX and XLSX. The only reliable differentiator is the content types override:
| Format | Main Document Part | Override Content Type |
|---|---|---|
| DOCX | word/document.xml |
...wordprocessingml.document.main+xml |
| PPTX | ppt/presentation.xml |
...presentationml.presentation.main+xml |
| XLSX | xl/workbook.xml |
...spreadsheetml.sheet.main+xml |
A file renamed from .pptx to .docx passes the ZIP signature check and contains valid XML parts, but the content types override points to the presentation namespace. Processors that validate the override will reject the file or treat it as a presentation regardless of extension. The file command on Linux (via libmagic) and Windows Explorer property handlers both perform this override check.