Sub topic 11
Size limits and sitemap index files
This chapter assumes you can read basic XML, know what a sitemap <urlset> looks like, and have seen a Sitemap: line in robots.txt. Here you will learn the hard limits on a sitemap file and how a sitemap index lets you go past them.
The limits
A single sitemap file has two limits, and a file must stay within both:
- At most 50,000 URLs.
- At most 50 MB when uncompressed.
The size limit applies to the uncompressed file. Compressing a sitemap with gzip (for example sitemap-blog.xml.gz) saves bandwidth, but it does not raise the limit. Crawlers decompress the file first and then check its size.
A sitemap index file has the same two limits, counted differently: it can list up to 50,000 sitemap files.
What a sitemap index is
A sitemap index is an XML file that lists other sitemap files. It uses the <sitemapindex> root element and one <sitemap> entry per file. Each entry has a <loc> (the absolute URL of a sitemap file) and an optional <lastmod>.
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://www.example.com/sitemap-pages.xml</loc>
<lastmod>2026-11-01</lastmod>
</sitemap>
<sitemap>
<loc>https://www.example.com/sitemap-blog.xml</loc>
<lastmod>2026-11-20</lastmod>
</sitemap>
</sitemapindex>You then submit only the index, or reference only the index in robots.txt. The crawler follows each <loc> to read the child sitemaps.
Rules for index files
- An index lists sitemap files only. It cannot list normal pages, and it cannot contain another index. Nesting indexes is not allowed.
- Every
<loc>must be an absolute URL. - Child sitemaps should live on the same site as the index, in the same host and protocol. The simplest safe choice is to put them in the same directory or higher than the index.
- The
<lastmod>in an index entry should match the newest<lastmod>in that child file. Update it only when the child really changed.
Choosing how to split
You can split by any rule that keeps each file under the limits. Splitting by content type is common, because it also helps you diagnose problems later: if the blog sitemap shows many errors, you know where to look.
| Strategy | Example files | Good for |
|---|---|---|
| By content type | `sitemap-pages.xml`, `sitemap-blog.xml`, `sitemap-products.xml` | Most sites, and easy debugging |
| By date | `sitemap-2026-10.xml`, `sitemap-2026-11.xml` | Archives where old files never change |
| By count | `sitemap-1.xml`, `sitemap-2.xml` | A single huge table of URLs |
Leave some room. Aim for about 40,000 URLs per file so that growth does not push a file over the limit between two runs of your generator.
Splitting in code
This script chunks a URL list and writes an index. It uses the same standard library tools as the earlier generator example, so ElementTree escapes special characters for you.
import xml.etree.ElementTree as ET
NS = "http://www.sitemaps.org/schemas/sitemap/0.9"
ET.register_namespace("", NS)
CHUNK = 40000
def write_xml(root, path):
ET.ElementTree(root).write(path, encoding="utf-8", xml_declaration=True)
def build(urls, base, lastmod):
index = ET.Element(f"{{{NS}}}sitemapindex")
for n, start in enumerate(range(0, len(urls), CHUNK), start=1):
urlset = ET.Element(f"{{{NS}}}urlset")
for loc in urls[start:start + CHUNK]:
url = ET.SubElement(urlset, f"{{{NS}}}url")
ET.SubElement(url, f"{{{NS}}}loc").text = loc
ET.SubElement(url, f"{{{NS}}}lastmod").text = lastmod
name = f"sitemap-{n}.xml"
write_xml(urlset, name)
entry = ET.SubElement(index, f"{{{NS}}}sitemap")
ET.SubElement(entry, f"{{{NS}}}loc").text = f"{base}/{name}"
ET.SubElement(entry, f"{{{NS}}}lastmod").text = lastmod
write_xml(index, "sitemap_index.xml")
urls = [f"https://www.example.com/item/{i}" for i in range(95000)]
build(urls, "https://www.example.com", "2026-11-01")With 95,000 URLs this writes three sitemaps (40,000, 40,000, and 15,000 URLs) plus sitemap_index.xml.
Common mistakes
- Counting only URLs and forgetting the 50 MB limit, especially with image or hreflang extensions that make each entry larger.
- Putting an index inside another index.
- Listing relative paths such as
/sitemap-blog.xmlinstead of absolute URLs. - Changing
<lastmod>on every run, so it no longer tells the crawler anything.
Exercise
A site has 120,000 URLs. Each sitemap file is capped at 50,000 URLs. How many sitemap files do you need at minimum, and what extra file do you need to reference them from robots.txt?
Show answer
You need at least 3 sitemap files (50,000 + 50,000 + 20,000). You also need a sitemap index file that lists the three files, and you reference that index with one Sitemap line in robots.txt. In practice, use smaller chunks such as 40,000 for headroom.
Exercise
Your sitemap has only 30,000 URLs, but the uncompressed file is 58 MB. Is it valid? How do you fix it?
Show answer
It is not valid, because the 50 MB uncompressed limit is exceeded even though the URL count is under 50,000. Gzip does not help, since the limit applies after decompression. Split the file into several smaller sitemaps and list them in a sitemap index.