How do I compress and split a large XML sitemap?

The Citead team, updated

In short. Split XML sitemaps at the URL or uncompressed size limit, compress each file with gzip, and optionally submit a sitemap index.

Definition: A large XML sitemap is split into separate, valid sitemap files that each meet the URL-count and uncompressed-size limits. Gzip compresses each file for transfer; a sitemap index is an XML file that lists the locations of those sitemap files.

Key facts

When must a sitemap be split?

Google's construction guide requires splitting when either the file-size limit or the URL-count limit is exceeded. A file containing fewer than 50,000 URLs still needs splitting if its uncompressed size exceeds 50 MB. A small gzip download therefore cannot resolve an oversized XML file.

Each resulting file follows the guide's XML sitemap format: a urlset root with the sitemap namespace, containing a url element and a loc element for each page. Each file uses UTF-8 encoding and fully qualified, absolute page URLs. The guide recommends generating larger sitemaps through website software and states that URL order does not matter to Google.

How are the files compressed and indexed?

The Sitemaps protocol permits gzip to reduce bandwidth requirements. It also limits an index to 50 MB and permits compression of the index itself.

For already separated files named sitemap1.xml and sitemap2.xml, these shell commands produce separate gzip files. The gzip manual documents -c as writing compressed output to standard output while keeping the original files; -t checks the resulting compressed files.

gzip -c sitemap1.xml > sitemap1.xml.gz
gzip -c sitemap2.xml > sitemap2.xml.gz
gzip -t sitemap1.xml.gz sitemap2.xml.gz

The following XML adapts Google's sitemap index example, omitting its optional modification dates. The sitemapindex root contains a sitemap element for each file, and each loc contains that file's URL.

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>https://www.example.com/sitemap1.xml.gz</loc>
  </sitemap>
  <sitemap>
    <loc>https://www.example.com/sitemap2.xml.gz</loc>
  </sitemap>
</sitemapindex>

Under the same documentation's standard hosting rules, the referenced files sit on the same site as the index, in its directory or deeper in the site hierarchy. Google provides a separate cross-site submission procedure for exceptions to the same-site requirement.

How is the index submitted and checked?

Google's construction documentation allows submission of a single sitemap index through Search Console. Its Sitemaps report shows when Googlebot accesses a submitted sitemap and reports potential processing errors. The same documentation also allows sitemap locations in robots.txt.

Google's index reference defines the optional index-level lastmod as the time the corresponding sitemap file changes. Its value follows W3C Datetime format.

FAQ

Can I keep one oversized sitemap if gzip makes it small enough?

The Sitemaps protocol applies the 50 MB limit after decompression. You still need separate sitemap files when the uncompressed XML exceeds that limit.

Must I create an index whenever I split a sitemap?

Google's construction guide makes the index optional. You can submit multiple sitemap files individually or submit a single index listing them.

What goes in an index's loc element?

Google's index example puts sitemap-file URLs there, including .xml.gz URLs. The page URLs belong in the individual sitemap files.

Sources

  1. Google Search Central, "Build and submit a sitemap", 8 July 2026
  2. Sitemaps.org, "Sitemaps XML format", 21 November 2016
  3. Google Search Central, "Manage your sitemaps with a sitemap index file", 10 December 2025
  4. Debian Manpages, "gzip(1)", source updated 17 August 2026

Check how a page reads to answer engines. Open the GEO score analyzer

Test a page and see what to fix first

The analysis usually takes less than 10 seconds and needs no account.

400,000+ pages scored in the public benchmark