<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>Compression in XLSX on File Format Blog</title>
    <link>https://blog.fileformat.com/tag/compression-in-xlsx/</link>
    <description>Recent content in Compression in XLSX on File Format Blog</description>
    <generator>Hugo -- gohugo.io</generator>
    <language>en</language>
    <lastBuildDate>Thu, 10 Sep 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://blog.fileformat.com/tag/compression-in-xlsx/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>How Compression Works Inside EPUB, DOCX, XLSX, and PPTX?</title>
      <link>https://blog.fileformat.com/compression/how-compression-works-inside-epub-docx-xlsx-and-pptx/</link>
      <pubDate>Thu, 10 Sep 2026 00:00:00 +0000</pubDate>
      
      <guid>https://blog.fileformat.com/compression/how-compression-works-inside-epub-docx-xlsx-and-pptx/</guid>
      <description>Ever wondered what&amp;#39;s under the hood of a .docx or .epub file? Explore how ZIP packaging and DEFLATE compression keep modern office documents and ebooks lightweight and organized. </description>
      <content:encoded><![CDATA[<p><strong>Last Updated</strong>: 10 September, 2026</p>
<figure class="align-center ">
    <img loading="lazy" src="images/how-compression-works-inside-epub-docx-xlsx-and-pptx.png#center"
         alt="How Compression Works Inside EPUB, DOCX, XLSX, &amp; PPTX: The Hidden ZIP Architecture"/> 
</figure>

<h2 id="how-compression-works-inside-epub-docx-xlsx-and-pptx">How Compression Works Inside EPUB, DOCX, XLSX, and PPTX</h2>
<p>If you rename a <code>.docx</code>, <code>.xlsx</code>, <code>.pptx</code>, or <code>.epub</code> file to <code>.zip</code> and double-click it, something surprising happens: it doesn’t throw an error. Your operating system opens it as a folder packed with subdirectories, XML configuration files, styling sheets, fonts, and embedded images.</p>
<p>Modern document architectures abandoned monolithic binary blobs decades ago. In their place, industry standards—namely <strong>Open Packaging Conventions (OPC)</strong> for Microsoft Office and the <strong>Open Container Format (OCF)</strong> for EPUB—adopted a surprisingly elegant foundation: the humble <strong>ZIP archive</strong>.</p>
<p>Understanding how compression operates inside these formats reveals why modern documents are so resilient, lightweight, and extensible—and why some files compress by 90% while others barely shrink at all.</p>
<h2 id="1-the-container-architecture-disguised-zip9-packages">1. The Container Architecture: Disguised <a href="https://docs.fileformat.com/compression/zip/">ZIP</a> Packages</h2>
<p>Before understanding the compression algorithm itself, it helps to understand why modern document formats are structured as packages rather than standalone raw files.</p>
<h3 id="the-problem-with-legacy-binary-formats">The Problem with Legacy Binary Formats</h3>
<p>Throughout the 1990s and early 2000s, Microsoft Office used proprietary binary formats (<code>.doc</code>, <code>.xls</code>, <code>.ppt</code>). These files were essentially memory dumps structured around the Compound File Binary Format (CFBF). They were notoriously fragile:</p>
<ul>
<li>A single bit flip could corrupt the entire file structure.</li>
<li>Embedding images caused file sizes to balloon unpredictably.</li>
<li>Parsing required reverse-engineering dense binary specifications.</li>
<li>Cross-platform interoperability was a nightmare.</li>
</ul>
<h3 id="the-shift-to-open-modular-containers">The Shift to Open, Modular Containers</h3>
<p>In the mid-2000s, two parallel evolutions took place:</p>
<ol>
<li><strong>Office Open XML (OOXML / ISO/IEC 29500):</strong> Microsoft introduced the XML-based formats ending with an <code>x</code> (<a href="https://docs.fileformat.com/word-processing/docx/">DOCX</a>, <a href="https://docs.fileformat.com/spreadsheet/xlsx/">XLSX</a>, <a href="https://docs.fileformat.com/presentation/pptx/">PPTX</a>). Under the hood, these files follow the <strong>Open Packaging Conventions (OPC)</strong>.</li>
<li><strong><a href="https://docs.fileformat.com/ebook/epub/">EPUB</a> (IDPF / W3C):</strong> Digital publishing moved away from proprietary reader formats toward standard web tech (HTML, CSS, SVG) bundled inside the <strong>EPUB Open Container Format (OCF)</strong>.</li>
</ol>
<p>Both architectures rely on standard <strong>PKZIP 2.0 / ZIP specification</strong>. The file extension simply dictates the expected schema, the default viewer application, and mime-type declarations.</p>
<pre tabindex="0"><code>Sample DOCX File (Unzipped):
├── [Content_Types].xml        &lt;-- Registry of MIME types for parts
├── _rels/                     &lt;-- Package-level relationships
│   └── .rels
├── docProps/                  &lt;-- Core and extended metadata
│   ├── app.xml
│   └── core.xml
└── word/                      &lt;-- Main content payload
    ├── document.xml           &lt;-- Text, paragraphs, and tags
    ├── styles.xml             &lt;-- Typography and presets
    ├── numbering.xml          &lt;-- Lists and counters
    ├── media/                 &lt;-- Embedded images (PNG, JPG)
    └── _rels/
        └── document.xml.rels  &lt;-- Internal hyperlinks &amp; resource pointers
</code></pre><h2 id="2-the-engine-under-the-hood-the-deflate-algorithm">2. The Engine Under the Hood: The DEFLATE Algorithm</h2>
<p>When a software application saves a DOCX or EPUB file, it doesn&rsquo;t just store files into an uncompressed archive. It compresses the internal assets using <strong>DEFLATE</strong> (specified in RFC 1951).</p>
<p>DEFLATE is a two-tier lossless compression system combining two fundamental computer science algorithms:</p>
<h3 id="step-1-lz77-lempel-ziv-1977--sliding-window-redundancy-removal">Step 1: LZ77 (Lempel-Ziv 1977) — Sliding Window Redundancy Removal</h3>
<p>XML and HTML are extremely verbose. Consider how often tags appear in a standard <code>document.xml</code> or <code>chapter1.xhtml</code> file:</p>
<ul>
<li><code>&lt;w:p&gt;&lt;w:r&gt;&lt;w:rPr&gt;&lt;w:sz w:val=&quot;24&quot;/&gt;&lt;/w:rPr&gt;&lt;w:t&gt;</code> repeats thousands of times in Word.</li>
<li><code>row r=&quot;1&quot; spans=&quot;1:15&quot;&gt;&lt;c r=&quot;A1&quot; t=&quot;s&quot;&gt;&lt;v&gt;</code> repeats in Excel across tens of thousands of cells.</li>
<li><code>&lt;p class=&quot;calibre1&quot;&gt;&lt;span class=&quot;body-text&quot;&gt;</code> repeats across EPUB book chapters.</li>
</ul>
<p>LZ77 scans the data stream using a sliding dictionary window (typically 32 KB). When it encounters a string of characters it has seen recently, it replaces the duplicate text with a tiny backward pointer:</p>
<ul>
<li><code>(distance, length)</code> — e.g., &ldquo;go back 142 bytes, copy 28 bytes&rdquo;.</li>
</ul>
<p>Instead of storing verbose markup over and over, LZ77 collapses thousands of repetitive XML tags into compact coordinate references.</p>
<h3 id="step-2-huffman-coding--variable-length-frequency-encoding">Step 2: Huffman Coding — Variable-Length Frequency Encoding</h3>
<p>After LZ77 replaces redundant sequences with length-distance tokens, <strong>Huffman coding</strong> analyzes the frequency of every symbol in the stream:</p>
<ul>
<li>Frequently appearing symbols (like common characters <code>e</code>, <code>t</code>, spaces, or common distance markers) are assigned short binary bit codes (e.g., 2 to 4 bits).</li>
<li>Rarely used symbols receive longer binary bit codes (e.g., 12 to 16 bits).</li>
</ul>
<p>The result is a stream of variable-length bit codes that squeeze plain-text XML down by <strong>75% to 88%</strong>.</p>
<h2 id="3-format-by-format-breakdown-how-each-handles-compression">3. Format-by-Format Breakdown: How Each Handles Compression</h2>
<p>While DOCX, XLSX, PPTX, and EPUB all use the same ZIP envelope, their internal data characteristics differ wildly.</p>
<h3 id="a-docx-the-text-and-styling-balancing-act">A. DOCX: The Text and Styling Balancing Act</h3>
<ul>
<li><strong>What’s inside:</strong> Plain XML (<code>word/document.xml</code>), font tables, styles, relationship catalogs, and a <code>word/media/</code> folder.</li>
<li><strong>How compression performs:</strong>
<ul>
<li>The raw text and XML markup experience massive compression ratios (often dropping from 5 MB of raw XML down to 500 KB).</li>
<li>However, modern documents often embed screenshots, illustrations, and photos. Because JPEG and PNG files are <strong>already compressed</strong>, DEFLATE cannot shrink them further. In fact, running DEFLATE over an already-compressed image yields virtually 0% savings (and can even slightly increase size due to compression headers).</li>
<li>Consequently, DOCX files without images are exceptionally tiny, whereas image-heavy reports reflect almost the exact size of their contained image files.</li>
</ul>
</li>
</ul>
<h3 id="b-xlsx-high-volume-numeric-data--shared-strings">B. XLSX: High-Volume Numeric Data &amp; Shared Strings</h3>
<p>Spreadsheets present a unique challenge: a sheet can contain hundreds of thousands of rows, leading to astronomical XML file sizes if not handled smartly.</p>
<ul>
<li><strong>The Shared Strings Strategy (<code>xl/sharedStrings.xml</code>):</strong>
<ul>
<li>If a text label like &ldquo;United States&rdquo; or &ldquo;In Progress&rdquo; appears 50,000 times in a spreadsheet, storing <code>&lt;c t=&quot;inlineStr&quot;&gt;&lt;is&gt;&lt;t&gt;United States&lt;/t&gt;&lt;/is&gt;&lt;/c&gt;</code> in 50,000 cells would bloat the uncompressed XML to gigabytes.</li>
<li>Excel deduplicates text before compression by storing every unique string once in a shared string table and referencing it by numerical index (e.g., <code>&lt;v&gt;0&lt;/v&gt;</code>, <code>&lt;v&gt;1&lt;/v&gt;</code>).</li>
</ul>
</li>
<li><strong>Why XLSX Compresses Dramatically:</strong>
<ul>
<li>Numeric row records (<code>sheet1.xml</code>) follow repetitive, predictable syntax.</li>
<li>DEFLATE easily detects repetitive patterns in tabular XML. It is common for a 120 MB raw <code>sheet1.xml</code> file to shrink to less than 6 MB inside an XLSX archive.</li>
</ul>
</li>
</ul>
<h3 id="c-pptx-media-heavy-slide-decks">C. PPTX: Media-Heavy Slide Decks</h3>
<p>Presentations are fundamentally different from documents and spreadsheets:</p>
<ul>
<li><strong>The Image Dilemma:</strong> PPTX files are typically dominated by vector shapes, background graphics, video clips, and high-resolution slides.</li>
<li><strong>Compression Profile:</strong> While <code>ppt/slides/slide1.xml</code> through <code>slideN.xml</code> compress efficiently, the media payload (<code>ppt/media/</code>) accounts for 85% to 95% of the total archive weight.</li>
<li><strong>Why Re-Zipping a PPTX Changes Nothing:</strong> If you try to compress an already-saved PPTX file with 7-Zip or WinRAR, you will notice almost no size reduction. Because the interior is already a DEFLATE-compressed ZIP archive containing pre-compressed JPEGs and MP4s, the entropy is already near maximum.</li>
</ul>
<h3 id="d-epub-web-technologies-with-a-mandatory-uncompressed-header">D. EPUB: Web Technologies with a Mandatory Uncompressed Header</h3>
<p>An EPUB file is essentially a responsive, packaged micro-website containing XHTML chapters, CSS stylesheets, TTF/WOFF fonts, and metadata. However, EPUB has one strict packaging rule that differentiates it from Microsoft Office files:</p>
<pre tabindex="0"><code>EPUB Internal Structure:
├── mimetype                    &lt;-- MUST be uncompressed (Stored) &amp; at byte offset 38
├── META-INF/
│   └── container.xml           &lt;-- Tells reader where the OPF manifest lives
└── OEBPS/ (or EPUB/)
    ├── content.opf             &lt;-- Manifest of all book assets
    ├── toc.ncx / nav.xhtml     &lt;-- Table of contents navigation
    ├── styles/style.css        &lt;-- CSS formatting
    ├── images/                 &lt;-- Book cover &amp; illustrations
    └── text/                   &lt;-- chapter1.xhtml, chapter2.xhtml
</code></pre><ul>
<li><strong>The Magic <code>mimetype</code> File:</strong>
<ul>
<li>E-readers need to identify an EPUB immediately without extracting the entire archive or running decompression pipelines.</li>
<li>The Open Container Format (OCF) mandates that the <code>mimetype</code> file:
<ol>
<li>Must be the very first file in the ZIP archive.</li>
<li>Must contain exactly the string <code>application/epub+zip</code>.</li>
<li><strong>Must not be compressed</strong> (ZIP compression method <code>0</code> / &ldquo;Stored&rdquo;).</li>
<li>Must have no extra field data, ensuring the MIME string always begins at byte 38 of the physical file.</li>
</ol>
</li>
</ul>
</li>
<li><strong>Text Compression:</strong> All remaining files (<code>.xhtml</code>, <code>.css</code>, <code>.opf</code>) are compressed using standard DEFLATE (ZIP method <code>8</code>), allowing full-length novels to shrink down to a few hundred kilobytes.</li>
</ul>
<h2 id="4-comparing-compression-across-formats">4. Comparing Compression Across Formats</h2>
<table>
<thead>
<tr>
<th style="text-align:left">Format</th>
<th style="text-align:left">Core Payload</th>
<th style="text-align:left">Primary Redundancy Source</th>
<th style="text-align:left">Typical Compression Ratio (Text/Markup)</th>
<th style="text-align:left">Media Handling</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><strong>DOCX</strong></td>
<td style="text-align:left">WordprocessingML (<code>document.xml</code>)</td>
<td style="text-align:left">Repetitive XML paragraph/run tags</td>
<td style="text-align:left">75% – 85%</td>
<td style="text-align:left">Stored in <code>word/media/</code> (mostly pre-compressed)</td>
</tr>
<tr>
<td style="text-align:left"><strong>XLSX</strong></td>
<td style="text-align:left">SpreadsheetML (<code>sheet*.xml</code>)</td>
<td style="text-align:left">Repetitive cell/row tags; Shared Strings</td>
<td style="text-align:left">80% – 92%</td>
<td style="text-align:left">Sparse; images/charts in <code>xl/media/</code></td>
</tr>
<tr>
<td style="text-align:left"><strong>PPTX</strong></td>
<td style="text-align:left">PresentationML (<code>slide*.xml</code>)</td>
<td style="text-align:left">Slide layout metadata, shape coordinates</td>
<td style="text-align:left">70% – 80%</td>
<td style="text-align:left">Heavy <code>ppt/media/</code> payload limits overall savings</td>
</tr>
<tr>
<td style="text-align:left"><strong>EPUB</strong></td>
<td style="text-align:left">XHTML, CSS, OPF, NCX</td>
<td style="text-align:left">HTML tags, repetitive CSS selectors</td>
<td style="text-align:left">65% – 80%</td>
<td style="text-align:left"><code>mimetype</code> uncompressed; media in subfolders</td>
</tr>
</tbody>
</table>
<h2 id="5-practical-takeaways-how-to-optimize-your-documents">5. Practical Takeaways: How to Optimize Your Documents</h2>
<p>Because you now know how internal packaging works, you can leverage compression mechanics to solve real-world problems:</p>
<ol>
<li><strong>Fixing Corrupted Documents:</strong>
If a document refuses to open, changing the extension to <code>.zip</code> allows you to extract the contents and recover the raw text from <code>document.xml</code> or individual chapters from the EPUB&rsquo;s <code>text/</code> directory.</li>
<li><strong>Shrinking Giant Office Files:</strong>
Since XML compression is already optimized, giant files are almost always caused by unoptimized images in <code>media/</code>. Rather than using third-party PDF or DOCX compressors, open the ZIP container, extract the images, run them through an image optimizer (like WebP, TinyPNG, or MozJPEG), and replace them inside the archive.</li>
<li><strong>Automating Document Generation:</strong>
Developers don&rsquo;t need heavyweight office suites to build reports. You can generate raw XML templates, bundle them using standard zlib/ZIP libraries, and output valid DOCX or XLSX files programmatically in milliseconds.</li>
</ol>
<h2 id="6-frequently-asked-questions-faq">6. Frequently Asked Questions (FAQ)</h2>
<p><strong>Can I convert a DOCX or EPUB to a ZIP file just by renaming the file extension?</strong>
Yes; renaming the extension to <code>.zip</code> allows any standard archive tool (like 7-Zip, macOS Archive Utility, or Windows Explorer) to open and inspect the internal files directly.</p>
<p><strong>Why doesn&rsquo;t compressing a DOCX or PPTX with 7-Zip make it noticeably smaller?</strong>
Because the file is already an internally compressed ZIP archive containing DEFLATE-encoded XML and pre-compressed images, leaving minimal redundancy for an external tool to remove.</p>
<p><strong>Why does the EPUB specification require the <code>mimetype</code> file to be uncompressed?</strong>
It allows e-reader software to verify that the file is an authentic EPUB by checking the MIME string at a fixed byte offset without having to initialize a decompression engine.</p>
<p><strong>Does changing cell formatting in Excel increase the compressed XLSX file size?</strong>
Yes; extensive custom formatting breaks uniform pattern repetition across cells, creating longer XML definitions that reduce DEFLATE&rsquo;s compression efficiency.</p>
<p><strong>Is it possible to extract high-resolution original images from a Word or PowerPoint file without quality loss?</strong>
Yes; rename the file to <code>.zip</code>, open the <code>word/media</code> or <code>ppt/media</code> folder, and you will find the original, uncompressed source images exactly as they were inserted.</p>
<h2 id="see-also">See Also</h2>
<ul>
<li><a href="https://blog.fileformat.com/compression/compression-file-formats-at-fileformat-com/">Compression File Formats at FileFormat.com</a></li>
<li><a href="https://blog.fileformat.com/compression/zip-bombs-exploding-your-storage/">ZIP Bombs – Exploding Your Storage</a></li>
<li><a href="https://blog.fileformat.com/compression/what-is-7z-file-format-comprehensive-guide-and-faqs/">Understanding 7z file format - Comprehensive Guide and FAQs</a></li>
<li><a href="https://blog.fileformat.com/compression/how-to-open-rar-files-with-best-rar-openers/">The 7 Best Tools to Open or Extract RAR Files</a></li>
</ul>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
