Split sitemap.xml once it passes 50,000 URLs | Files of 50,000 URLs each and a sitemap index
A single sitemap can hold at most 50,000 URLs or 50 MB uncompressed. This walkthrough splits a 120,000-URL sitemap.xml with the XML Splitter at the <url> level into three files of up to 50,000 URLs, keeping the namespaces and hreflang xhtml:link elements intact, then checks the output and shows how to write the sitemap index.
Contents
If you write every product or article URL into a single sitemap.xml with your own script or your system’s export feature, there may come a day, once the count has grown, when Search Console can no longer read the sitemap. A single sitemap file has limits on both the number of URLs and the file size, and once you exceed them you have to split it into several files.
The proper fix is to change the program that generates the sitemap so it writes split files from the start. But sometimes you can’t touch the export process right away and simply want to resubmit the file you already have. This article takes a finished sitemap.xml, splits it into files of 50,000 URLs each with the XML Splitter, and writes a sitemap index to submit them together, with the results of actually trying it on a 120,000-URL sitemap.
The limit per sitemap file is 50,000 URLs and 50 MB uncompressed
Google’s guide to building and submitting a sitemap states that, whatever the format, a sitemap is limited to 50 MB (uncompressed) or 50,000 URLs per file. If the file is larger or has more URLs, you split it into several sitemaps and, optionally, submit a single sitemap index file that lists them. The sitemaps.org protocol, which defines the sitemap format, also caps a file at 50,000 URLs and 50 MB (52,428,800 bytes). You can serve the files gzip-compressed, but the 50 MB limit applies to the size before compression.
To decide how to split, first check which limit your file is hitting. The number of URLs is the number of <loc> elements, and the XML Splitter also shows the count when it loads the file. The file size is shown in your operating system’s file information.
Trying it on a 120,000-URL sitemap
The test file was a sitemap listing 120,000 product pages for a fictional online shop, shop.example.com. I generated it with a Python script. Besides <loc> and <lastmod>, each <url> contains two xhtml:link (hreflang) elements that pair the Japanese and English versions of the page, a pattern common in sitemaps for multilingual sites.
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://shop.example.com/items/000001/</loc>
<lastmod>2026-01-02</lastmod>
<xhtml:link rel="alternate" hreflang="ja" href="https://shop.example.com/items/000001/"/>
<xhtml:link rel="alternate" hreflang="en" href="https://shop.example.com/en/items/000001/"/>
</url>
<!-- 120,000 <url> elements of the same shape follow -->
</urlset>
The file is 35,520,153 bytes (about 33.9 MiB), so it fits under 50 MB. Only the URL count is over the limit, so splitting by count at 50,000 per file is enough. With 120,000 URLs, that should give three files of 50,000, 50,000 and 20,000.
When splitting, every file must keep the <?xml ...?> declaration and a <urlset> carrying both xmlns and xmlns:xhtml. A <url> must not be cut in the middle, and its xhtml:link elements must not end up in a different file. Cutting the text by line count can’t guarantee this, so the split has to read the XML structure and divide it by repeated elements.
Check that the split unit is <url>
- Open the XML Splitter and choose
sitemap.xmlunder “XML input file”. - Leave “Record selection mode” at “Auto (most records)”. After reading the whole file and examining the candidates, the tool selects
/urlset/urlwith 120,000 records. - Open “Input preview (encoding and structure)” and confirm that the encoding is detected as UTF-8 and that
<url>elements are lined up inside<urlset>.
By raw count there are 240,000 xhtml:link elements, more than there are <url> elements. They still don’t appear as a candidate because the tool only treats “same-named elements lined up consecutively under one parent” as a split unit. The xhtml:link elements are scattered two at a time under each of the 120,000 <url> elements, so they don’t qualify and travel along as part of each <url>.
The same applies to image or video sitemaps, where other elements are nested inside <url>. If auto-selection picks an element you didn’t intend, choose again under “Choose detected candidate”, or select “Specify element path manually” and enter /urlset/url.
Split at 50,000 records per file and save
Next, set the split condition and how to save the files.
- Set “Split by” to “Maximum records (rows)” and enter
50000in “Maximum records per file”. What gets counted here is<url>elements, not line breaks in the file. - Set “Output encoding” to “UTF-8 (no BOM)”. Sitemaps must be written in UTF-8, so if the original is UTF-8 you can leave it as is.
- Choose a “Saving method”. This time I used “Download files individually”. In a supported desktop browser, “Save directly to folder (large files)” writes all the files at once into a dedicated folder created under the folder you choose.
- Click “Validate and split”. Once the whole file has been validated, the name, record count and byte size of the first file appear.
- Click “Save this file”, wait for the browser download to finish, then click “Confirm save and continue”. For the last file the button reads “Confirm save and finish”.
When all three files are saved, the output results list the record count and byte size of each file.
Each file name is the original name plus a sequence number such as _part_000001. The total is 312 bytes more than the original 35,520,153 bytes mainly because the second and third files also get the XML declaration and the opening and closing <urlset> tags.
Check that the split files still read as sitemaps
Before submitting, confirm that each of the three files is valid XML and that no URL has gone missing or been duplicated. I checked the following:
- All three files loaded as well-formed XML with
xmllint --noout. - Each file begins with
<?xml version="1.0" encoding="UTF-8"?>and a<urlset>that carries bothxmlnsandxmlns:xhtml. - The files contain 50,000, 50,000 and 20,000
<url>elements, and the<loc>values of all three together make 120,000 unique URLs. The first and last URLs of the original (000001and120000) are included. - The
<lastmod>and the twoxhtml:linkelements inside each<url>are unchanged.
The start of the second file looked like this:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml">
<url>
<loc>https://shop.example.com/items/050001/</loc>
The whitespace-only line right after <urlset> comes from the line break and indentation that sat between two <url> elements in the original file, which travel along with the following <url>. It doesn’t change the meaning of the XML.
If you have a command line at hand, you can count URLs with something like grep -c '<loc>' sitemap_part_000001.xml. For files that don’t put one <loc> per line, use grep -o '<loc>' filename | wc -l.
Combine the three files with a sitemap index
Put the three files in your site’s public directory. You can keep names like sitemap_part_000001.xml or rename them to something clearer, such as sitemap-items-1.xml.
You could submit the three files to Search Console one by one, but re-registering every time the count grows to four or five files gets tedious. Instead, create one sitemap index that lists the files and submit that. The format is described in Google’s explanation of sitemap index files.
<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<sitemap>
<loc>https://shop.example.com/sitemap_part_000001.xml</loc>
</sitemap>
<sitemap>
<loc>https://shop.example.com/sitemap_part_000002.xml</loc>
</sitemap>
<sitemap>
<loc>https://shop.example.com/sitemap_part_000003.xml</loc>
</sitemap>
</sitemapindex>
In <loc>, write the full URL of each file you placed. If you want to signal when each file was updated, you can add <lastmod> inside <sitemap>. Put the index somewhere under a name such as sitemap_index.xml and submit that URL in Search Console’s Sitemaps report. You can also announce its location by adding Sitemap: https://shop.example.com/sitemap_index.xml to robots.txt.
If you had been submitting the 120,000-URL sitemap.xml, remove it from the sitemap list in Search Console so the oversized file doesn’t stay registered, and clean the file out of the public directory too.
On sites with long URLs, check the 50 MB limit as well
This sitemap used about 300 bytes per URL, so even at 50,000 URLs a file came to only about 14.8 MB. On sites with long URLs, many language versions listed as xhtml:link on every page, or lots of image information, 50,000 URLs can still reach 50 MB.
The XML Splitter lets you choose either a count or a size as the split condition, not both. Since the output results show the record count and byte size of every file, check in that table that each file is 52,428,800 bytes or less if you split by count, or 50,000 records or less if you split by size. To split by size, set “Maximum size per file” to 50 with the unit “MiB” (52,428,800 bytes), or to something smaller for a safety margin. The size limit is calculated including the XML declaration and <urlset> tags added to each file.
If a file exceeds either limit, split again with a smaller value matched to the other limit. For example, if a count-based split produced a file over 50 MB, specify fewer than 50,000 records.
So you don’t repeat this at every update
As products are added, the sitemap’s URL count will grow again. Splitting locally and re-uploading works as a stopgap until the export is fixed, but you end up repeating the same work at every update. And because the split points are decided by count, the URLs that land in each file shift from the previous run as products are added.
Once you can change the system that generates the sitemap, build the splitting into it so it writes a new file every 50,000 URLs plus an index. Some CMSs, such as WordPress’s built-in sitemaps, already split URLs into separate files at a fixed count and output an index. If you generate sitemaps with your own script, you can take the index and files built here as the target format.
Beyond sitemaps, the XML Splitter also works for product feeds and data-exchange XML where the destination limits the number of records or the size per file. To split JSON data in the same way, see how to split a large JSON file for import; for CSV, see the example of splitting a freee Sales product master CSV into batches of 999 (freee is a cloud accounting and sales service widely used in Japan). If you want to work with XML in another format while checking its contents, the article on converting XML to JSON and checking arrays and types shows how to use the XML⇔JSON converter.