ByteScope

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

0x00000000504B0304PK··'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

OffsetLengthFieldMeaning
04Local file header signature50 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.
42Version needed to extract0A 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.
62General purpose bit flag00 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.
82Compression method00 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.
102Last modified timeMS-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.
122Last modified dateMS-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.
144CRC-326F 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.
184Compressed size14 00 00 00, twenty bytes. Equal to the uncompressed size because the entry is stored.
224Uncompressed size14 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.
262File name length08 00, eight bytes, for the name 'mimetype'. Fixed by the specification, which requires that exact lowercase ASCII name.
282Extra field length00 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.
308Entry nameThe ASCII bytes 'mimetype'. It must be the first entry in the archive, so no other file may precede it.
3820Media type stringThe 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.
variablevariableMETA-INF/container.xmlThe 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.
-224End of central directory signature50 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 withHow to tell
ZIPEvery 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/AZWAmazon'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.
PDFThe 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.

FormatFirst bytesExtension
ZIP50 4B 03 04.zip
Word document (docx)50 4B 03 04.docx
HTMLno fixed signature.html

Frequently asked questions

What is a magic number in a file?

The first few bytes of a file, which identify its format regardless of what the name says. A PNG always starts with 89 50 4E 47; a ZIP with 50 4B 03 04. Operating systems, browsers and the file command all read these bytes rather than trusting the extension, which is why renaming a file does not change what it actually is.

How do I check a file's magic number myself?

On macOS or Linux, xxd -l 16 yourfile prints the first 16 bytes; on Windows, Format-Hex -Path yourfile -Count 16 in PowerShell. Or drop the file into the File Type Identifier on this site, which reads the bytes locally and names the format for you — nothing is uploaded.

Why do two formats share the same magic number?

Because one is built on the other. Every docx, xlsx, pptx, apk, jar and epub begins with the ZIP signature, since all of them are ZIP archives underneath; telling them apart means looking at the entries inside. Java class files and macOS universal binaries both start with CA FE BA BE and are distinguished by the field that follows.

Can a file have no magic number at all?

Yes. Text-based formats — XML, HTML, JSON, SVG, CSV — have no fixed byte signature, so they are recognized structurally instead: a leading <?xml declaration, a <svg element, or a { followed by a quoted key. That detection is a good guess rather than a certainty, which is why this reference marks those formats as probe-detected.

Does a matching magic number mean the file is safe?

No. It tells you what the format is, not whether the contents are harmless — a genuine PDF or docx can still carry a malicious payload. Identifying the true type is a useful first check, especially when the extension disagrees with the bytes, but it is not a malware scan.

Have a file that might be in the EPUB format? Identify it with the File Type Identifier — it reads the magic number locally, nothing is uploaded. Or browse all formats.