EPUB file format
An EPUB e-book — a ZIP archive containing XHTML content and a manifest.
- MIME type
- application/epub+zip
- Extensions
- .epub
- Category
- Documents
Magic-number signature
| 0x00000000 | 504B0304 | PK·· | 'PK' — it is a ZIP |
Inside the ZIP: a 'mimetype' entry whose contents are 'application/epub+zip'.
About the EPUB format
EPUB is the open e-book standard, and structurally it is a website in a ZIP: reflowable XHTML documents, CSS, fonts and images, plus a package document that lists every resource and the reading order. Unlike every other ZIP-based format, EPUB's container specification pins the archive's first bytes down exactly, so an EPUB is one of the few container formats that can be identified from the header alone rather than from its directory listing. That was a deliberate choice, made so that a server or a detector could recognise the type without decompressing anything.
Header layout, byte by byte
| Offset | Length | Field | Meaning |
|---|---|---|---|
| 0 | 4 | Local file header signature | 50 4B 03 04. An EPUB is an ordinary ZIP archive; everything below is the ZIP local file header for its first entry, which the OCF specification constrains far more tightly than ZIP itself does. |
| 4 | 2 | Version needed to extract | 0A 00, ten, because the first entry must be stored rather than deflated and stored entries need only version 1.0. Seeing 14 00 here means the writer compressed the mimetype entry and the package is already non-conforming. |
| 6 | 2 | General purpose bit flag | 00 00. The mimetype entry may not use a data descriptor, so bit 3 is clear and the CRC and sizes below are real values rather than zeroes. This is what makes the whole header deterministic. |
| 8 | 2 | Compression method | 00 00 — stored, uncompressed. The specification requires it, precisely so that the media type string appears as readable ASCII at a fixed position in the file rather than inside a deflate stream. |
| 10 | 2 | Last modified time | MS-DOS packed time. This is the one part of the header the specification leaves free, so it varies between files while everything around it does not. |
| 12 | 2 | Last modified date | MS-DOS packed date, year counted from 1980. Also unconstrained by OCF, and equally uninformative — the book's real dates live in the package document's metadata. |
| 14 | 4 | CRC-32 | 6F 61 AB 2C, that is 0x2CAB616F little-endian, in every conforming EPUB — because the entry's contents are fixed, so its checksum is a constant. A different value here means the mimetype file does not hold exactly the expected twenty bytes. |
| 18 | 4 | Compressed size | 14 00 00 00, twenty bytes. Equal to the uncompressed size because the entry is stored. |
| 22 | 4 | Uncompressed size | 14 00 00 00, twenty — the byte length of the string application/epub+zip with no trailing newline. A file with a stray newline here fails validation for a reason that is invisible in a text editor. |
| 26 | 2 | File name length | 08 00, eight bytes, for the name 'mimetype'. Fixed by the specification, which requires that exact lowercase ASCII name. |
| 28 | 2 | Extra field length | 00 00. The specification forbids an extra field on this entry, which is what guarantees the media type string lands at offset 38 and not somewhere further along. |
| 30 | 8 | Entry name | The ASCII bytes 'mimetype'. It must be the first entry in the archive, so no other file may precede it. |
| 38 | 20 | Media type string | The literal ASCII application/epub+zip. Six independent conditions have to hold for it to be here — stored, no extra field, no data descriptor, that exact name, that exact length, first in the archive — which together make the twenty bytes at offset 38 a far stronger identification than the 'PK' at offset 0. |
| variable | variable | META-INF/container.xml | The second required entry, though not at a fixed offset. It is the only file whose location the reader knows in advance, and it exists solely to point at the package document — commonly OEBPS/content.opf — which in turn lists the manifest and the spine, the ordered reading sequence. |
| -22 | 4 | End of central directory signature | 50 4B 05 06, twenty-two bytes from the end with no archive comment. Despite the fixed head, an EPUB is still a ZIP: readers enumerate its resources from the central directory at the tail, so a truncated file will not open even though its first fifty-eight bytes are perfect. |
Telling it apart from its neighbours
| Easily confused with | How to tell |
|---|---|
| ZIP | Every EPUB is a ZIP; almost no ZIP is an EPUB. The test is unusually strong because OCF fixes the whole first entry: method 0 at offset 8, name length 8 at 26, extra length 0 at 28, 'mimetype' at 30 and application/epub+zip at 38, with the constant CRC 0x2CAB616F at 14. A general-purpose archive will not satisfy all six by accident. |
| Word document (docx) | Both are ZIP packages of XML and both trip naive detectors that stop at 'PK'. OOXML pins nothing at byte level and is identified by [Content_Types].xml appearing at the package root — usually at offset 30 — while EPUB pins its whole first entry. If offset 30 reads 'mimetype' you have an EPUB; if it reads '[Content_Types].xml' you have OOXML. |
| MOBI/AZW | Amazon's older e-book formats, and not ZIPs at all: a PalmDOC-derived container with the ASCII string 'BOOKMOBI' at offset 60, or KF8/AZW3 which wraps the same container. Kindle devices read those and, until relatively recently, would not read EPUB at all, which is why the same book gets distributed in both. |
| The two e-book delivery formats, and opposites by design. A PDF fixes every glyph to a coordinate on a fixed page; an EPUB is XHTML that reflows to the screen and the reader's chosen font size. That is why a PDF is right for a document that must look identical everywhere and wrong on a phone, and why EPUB is the reverse. |
How these files break
- The mimetype entry compressed or moved. The commonest way to break an EPUB is to rebuild it with an ordinary zip command, which deflates every entry and may reorder them. The archive is a perfectly valid ZIP and readers reject it, because the media type string is no longer plain ASCII at offset 38. Building one correctly means adding mimetype first with no compression, then everything else.
- The archive tail is missing. The first fifty-eight bytes identify the file beautifully and the book still will not open, because a reader enumerates resources from the central directory at the end. Carving forward from 50 4B 03 04 and rebuilding the directory recovers the XHTML in full.
- META-INF/container.xml is absent or points at a package document that is not there. Everything else in the archive can be intact — chapters, images, stylesheets — and the reader has no entry point, so the book appears empty. This is a broken pointer rather than damaged data, and it is repairable by hand.
- A manifest that does not match the archive. Every resource must be declared in the package document; a chapter present in the ZIP but missing from the manifest simply never appears, and a manifest entry with no matching file makes strict readers refuse the whole book. Neither shows up as corruption in any ZIP tool.
- Text-mode transfer. Line-ending translation leaves every fixed header field readable — mimetype is stored, so it survives literally — while quietly damaging the deflate streams of the chapters. The book is identified correctly, opens, and then fails on a CRC mismatch partway through.
Where the format stands today
EPUB is the e-book standard everywhere except inside Amazon's ecosystem: it is what libraries lend, what publishers deliver, what Apple Books, Kobo, Google Play Books and every open-source reader consume, and since 2022 what Kindle accepts for personal documents. Version 3 brought it much closer to the web it was always built on — HTML5, CSS3, embedded fonts, MathML, media overlays for read-along audio, and enough scripting for interactive textbooks. Its defining property is reflow: text adapts to any screen size and any font size the reader chooses, which is exactly what a novel on a phone needs and exactly what a PDF cannot do. That same property makes it the wrong choice for anything whose layout carries meaning — technical books with precise figures, sheet music, comics and anything print-ready still ship as PDF, and EPUB's fixed-layout profile is a workaround rather than a strength. The one thing to know before treating an EPUB as a plain ZIP is that repacking it with an ordinary zip command will break it, because the first entry's storage method is part of the specification rather than an implementation detail.
Open EPUB files on this site
Every one of these runs in your browser — the file never leaves your machine.
Related formats
Formats that are easy to confuse with EPUB — compare their leading bytes.
| Format | First bytes | Extension |
|---|---|---|
| ZIP | 50 4B 03 04 | .zip |
| Word document (docx) | 50 4B 03 04 | .docx |
| HTML | no fixed signature | .html |