Skip to content

ZIP vs. DOCX File Signatures: Why Both Start With PK

ZIP and DOCX can share the same PK header. Check the package relationships, content types, and main document part to identify a DOCX.

By Sourabh4 min read

A ZIP archive and a DOCX document can both begin with 50 4B 03 04. Those bytes mark a ZIP local file header. A DOCX uses ZIP to package a Word document, so identifying it takes one more step. Inspect the package's relationships and content types to see what the container holds.

What the ZIP Signature Identifies

In a hex view, 50 4B appears as the letters PK. The full four-byte sequence 50 4B 03 04 identifies a local file header. The initial bytes can support a ZIP-family identification. A typical empty archive starts at its end-of-central-directory record, 50 4B 05 06.

Teaching diagram using the sample bytes. Both files begin with a ZIP local file header.

A header is one piece of structural evidence. Use a ZIP reader to see whether the package has a readable directory and internally consistent entries. The extension is a label that can disagree with the bytes.

What Inside the Package Identifies a DOCX?

Scroll horizontally if needed to see the full table.

Package itemWhat to check
[Content_Types].xmlThe document's main part is declared as the DOCX WordprocessingML document type
_rels/.relsThe package-level office document relationship targets the main part
word/document.xmlThis common main-part path exists in the example and contains WordprocessingML

Start with the package-level relationship and follow its target. A familiar filename alone can occur in a generic ZIP. The corresponding main part should exist and its declared content type should agree with the package type. Spreadsheet and presentation packages also use ZIP and XML, so seeing some XML files is an incomplete identification.

Teaching diagram. The package relationship points to the main part, and the content types file identifies its type.

Compare Two Benign Local Files

Create notes.zip from a small notes.txt file. In a word processor, save a one-line document as an ordinary, unencrypted note.docx. In the folder holding both files, run the following with Python 3. It prints the first four bytes and checks the archive directory without unpacking files or launching the document.

python
from pathlib import Path
from zipfile import ZipFile

for path in map(Path, ("notes.zip", "note.docx")):
    with path.open("rb") as file:
        print(path.name, file.read(4).hex(" ").upper())

    with ZipFile(path) as package:
        names = set(package.namelist())
        for name in ("notes.txt", "[Content_Types].xml",
                     "_rels/.rels", "word/document.xml"):
            print(f"  {name}: {name in names}")

The example was checked with Python 3.14.0 using small local teaching samples. Both files began with 50 4B 03 04. The ZIP listed notes.txt. In the DOCX, the three named package items were present. A word processor may add other parts.

Teaching illustration based on the verified local samples. The DOCX directory lists three package items that the plain ZIP lacks.

For the known-local DOCX sample, read the two small XML metadata files in memory. The standard DOCX main document part is declared as application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml. In the teaching sample, the package-level office document relationship points to word/document.xml.

python
from zipfile import ZipFile

with ZipFile("note.docx") as package:
    for name in ("_rels/.rels", "[Content_Types].xml"):
        print(name)
        print(package.read(name).decode("utf-8-sig"))

These snippets inspect the benign teaching files. Use the directory listing and relationship check together to distinguish a readable ZIP container from a package consistent with DOCX. File-type identification is a separate result from a full format validation.

What if the Header, Extension, and Package Disagree?

Suppose the extension is .docx and the first four bytes describe a ZIP local header. The central directory opens, but the only item is notes.txt. You have a readable ZIP with no evidence of the main document relationship in this check. Put both observations in your notes.

Now suppose a file ends in .zip, but the content type and package relationship identify a WordprocessingML document and its main part. The stored extension is still part of the original record. Describe the contents separately so the reader can see the discrepancy.

For a damaged sample, the signature might survive even when the central directory cannot be read. Record which evidence remains available. A few recognizable bytes alone give you less support than a verified relationship and a readable main part. The file carving and recovery comparison explains why a recovered fragment may still need structural validation.

Some password-encrypted Office documents use a compound-file wrapper instead of starting with the ordinary ZIP signature. This exercise tests unencrypted packages. If a file has neither the expected ZIP header nor a readable package, keep the door open to other formats or an encrypted wrapper.

Use the magic bytes walkthrough if you need help locating the first bytes. When you record your result, name the header, the metadata entries you checked, and the package type those entries support.

Was this page helpful?