Sub topic 11
Size limits and sitemap index files
This chapter assumes you can read basic XML, know what a sitemap urlset with url and loc entries looks like, and understand how crawlers fetch files over HTTP. It covers the hard limits on a sitemap file, how a sitemap index groups many files, and the mistakes that cause large sites to see sitemaps rejected or partly ignored.
The two hard limits
The sitemap protocol sets two limits on every sitemap file:
- At most 50,000 URLs per file.
- At most 50 MB per file, measured uncompressed.
A file that breaks either limit may be rejected or only partly read. Search engines document this behavior in slightly different ways, so treat the limits as a ceiling and not as a target.
Compression does not raise the 50 MB limit. You may serve a sitemap as sitemap.xml.gz to save bandwidth, but the crawler measures the size after it decompresses the file.
| Limit | Value | Counted how |
|---|---|---|
| URLs per sitemap file | 50,000 | Number of `url` entries |
| File size | 50 MB (52,428,800 bytes) | Uncompressed bytes |
| Sitemaps per index file | 50,000 | Number of `sitemap` entries |
| Index file size | 50 MB | Uncompressed bytes |
Which limit you hit first depends on your content. A site with short URLs and only loc and lastmod reaches 50,000 URLs at roughly 8 to 10 MB. A site with long URLs, image extensions, or hreflang alternates can reach 50 MB well before 50,000 URLs.
What a sitemap index is
A sitemap index is an XML file that lists other sitemap files. It uses a sitemapindex root element, and each child is a sitemap element with a loc. It may also have a 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>The index does not list page URLs. It only points to child sitemaps. A crawler fetches the index, then fetches each child file it lists.
Rules for index files
- An index may list at most 50,000 sitemaps, and the index file must stay under 50 MB uncompressed.
- An index cannot list another index. Nesting is not allowed, so the structure is always one level deep.
- Every
locmust be an absolute URL, including the scheme and host. - Child sitemaps must be on the same host as the index, or the owner must prove control of the other host (for example by referencing the sitemap from that host's
robots.txt). A sitemap athttps://www.example.com/should not list URLs fromhttps://shop.example.net/without that proof. - A sitemap file can only list URLs at or below its own location path unless it was submitted through a tool or
robots.txt. For example,https://www.example.com/blog/sitemap.xmlis expected to list URLs under/blog/. Placing sitemaps at the site root avoids this restriction.
With both limits at 50,000, one index can cover up to 2.5 billion URLs. Few sites come close to that.
Deciding how to split
You must split when you exceed a limit. You may also split earlier, because smaller files are easier to manage and to debug.
Common ways to split:
- By content type. Pages, blog posts, products, categories. This helps you see which section has indexing problems.
- By section or directory.
/docs/,/shop/,/news/. - By date. One file per month or year for archives. Older files rarely change, so their
lastmodstays stable. - By chunk. When one type has more than 50,000 URLs, number the files:
sitemap-products-1.xml,sitemap-products-2.xml.
Splitting by type or section is a monitoring tool as well as a size fix. If a search console report shows that most URLs from sitemap-products-2.xml are not indexed, you know where to look.
Keep each URL stable in its file when you can. If URLs move between chunks every time you regenerate, the child files' lastmod values change for no reason, and crawlers lose the signal that a file is unchanged.
Choosing a chunk size
A hard cap of 50,000 is a ceiling. Many sites use a lower number such as 10,000 or 25,000 per file, for these reasons:
- Smaller files are faster to generate, upload, and parse.
- With extensions (images, video, hreflang), the 50 MB limit arrives early. A lower URL count keeps a safety margin.
- A failed or corrupt file affects fewer URLs.
Measure before you choose. Count the bytes of a sample chunk and scale from there.
Generating an index with a script
The script below splits a list of URLs into chunks, writes each chunk as a sitemap file, and then writes an index that points to them. It uses ElementTree, which escapes characters such as & in URLs automatically.
import xml.etree.ElementTree as ET
from pathlib import Path
NS = "http://www.sitemaps.org/schemas/sitemap/0.9"
ET.register_namespace("", NS)
MAX_URLS = 50000
MAX_BYTES = 50 * 1024 * 1024
def write_xml(root, path):
ET.ElementTree(root).write(path, encoding="utf-8", xml_declaration=True)
def build_sitemaps(pages, base_url, out_dir, chunk_size=10000):
"""pages: list of (loc, lastmod). Returns the path of the index file."""
if chunk_size > MAX_URLS:
raise ValueError("chunk_size cannot exceed 50,000")
out = Path(out_dir)
out.mkdir(parents=True, exist_ok=True)
index = ET.Element(f"{{{NS}}}sitemapindex")
for n, start in enumerate(range(0, len(pages), chunk_size), start=1):
chunk = pages[start:start + chunk_size]
urlset = ET.Element(f"{{{NS}}}urlset")
for loc, lastmod in 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, out / name)
size = (out / name).stat().st_size
if size > MAX_BYTES:
raise RuntimeError(f"{name} is {size} bytes; lower chunk_size")
entry = ET.SubElement(index, f"{{{NS}}}sitemap")
ET.SubElement(entry, f"{{{NS}}}loc").text = f"{base_url}/{name}"
newest = max(lastmod for _, lastmod in chunk)
ET.SubElement(entry, f"{{{NS}}}lastmod").text = newest
index_path = out / "sitemap_index.xml"
write_xml(index, index_path)
return index_path
pages = [
(f"https://www.example.com/item/{i}", "2026-11-01") for i in range(25000)
]
print(build_sitemaps(pages, "https://www.example.com", "out", chunk_size=10000))With 25,000 pages and a chunk size of 10,000, the script writes three child files and one index. The index lastmod for each child is the newest lastmod inside it. This works because the dates are all in the same format, so string comparison matches date order. If you mix date-only and full datetime values, parse them before comparing.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| "Too many URLs" or file rejected | More than 50,000 `url` entries | Split the file and add an index |
| "File too large" with fewer than 50,000 URLs | Over 50 MB uncompressed, often from extensions | Lower the chunk size |
| Index reported as invalid | Index lists another index | Flatten to one level of children |
| Child sitemap not read | Relative `loc`, wrong scheme, or wrong host | Use absolute URLs that match the canonical host |
| Parse error on a valid-looking file | Unescaped `&`, `<` or `>` in a URL | Escape the characters, or build the XML with a library |
| Child file returns 404 or 5xx | Index generated before the children were uploaded | Upload children first, then the index |
| Many URLs "discovered" but unchanged | `lastmod` set to the build time on every run | Use the real modification date |
Operational details
- Order of publishing. Write child files first and the index last. A crawler that fetches a new index before its children exist gets errors.
- Serving. Serve each file with a
200status and an XML content type. Redirects on sitemap URLs are better avoided. - Compression. Gzip is allowed. Serve the
.xml.gzfile as-is, and keep the uncompressed size under 50 MB. - Dynamic sitemaps. Generating a very large sitemap on each request can time out. Pre-generate files and cache them, or generate them on a schedule.
- Duplicates. Do not list the same URL in several child files. It wastes the limit and confuses reports.
- Which URLs. List only canonical, indexable URLs that return
200. Redirected, blocked, ornoindexURLs do not belong in the sitemap.
Checking your files
Before you publish, run three checks:
- Count the
urlentries in each child. None may exceed 50,000. - Check the uncompressed byte size of each file, including the index.
- Fetch the index and every child over HTTP and confirm each returns
200.
A small script can automate the first two checks:
import sys
import xml.etree.ElementTree as ET
from pathlib import Path
NS = {"s": "http://www.sitemaps.org/schemas/sitemap/0.9"}
for name in sys.argv[1:]:
path = Path(name)
root = ET.parse(path).getroot()
count = len(root.findall("s:url", NS)) + len(root.findall("s:sitemap", NS))
size = path.stat().st_size
status = "OK" if count <= 50000 and size <= 50 * 1024 * 1024 else "TOO BIG"
print(f"{name}: {count} entries, {size} bytes, {status}")Run it as python check_sitemaps.py out/*.xml. Counting both url and sitemap children lets the same script check child files and the index.
Exercise
A site has 180,000 product URLs. Each URL entry, with loc, lastmod, and two image entries, averages about 600 bytes. Does one sitemap work? Design a split that stays within both limits, and say how the files are referenced.
Show answer
One file does not work. 180,000 exceeds the 50,000-URL limit, and 180,000 × 600 bytes is about 108 MB, which exceeds the 50 MB limit. Each chunk must satisfy both: 50 MB divided by 600 bytes allows about 87,000 entries, so the URL limit of 50,000 is the tighter one. A safer chunk size is 20,000 to 25,000, which gives 8 or 9 files (for example 9 files of 20,000 URLs, each about 12 MB). Name them sitemap-products-1.xml to sitemap-products-9.xml, list them in one sitemapindex file with absolute URLs, and add a Sitemap: line for the index in robots.txt. The index cannot point to another index.
Exercise
Your index file lists https://www.example.com/sitemaps/all.xml, and that file is itself a sitemap index. What happens, and how do you fix it?
Show answer
Nested indexes are not allowed, so crawlers may report the index as invalid or ignore the nested one. Fix it by listing the child sitemaps (the urlset files) directly in the top-level index, so the structure is one index with one level of children.