SEO2,586 words

How to create an XML sitemap: format, limits and submission

How to build, validate and submit an XML sitemap: what to list, size limits, sitemap indexes, lastmod and robots.txt.

ContentsWhat is an XML sitemap, and do you need one?

On this page0% read

how to create an xml sitemap guide

To create an XML sitemap, you build a UTF-8 file with a <urlset> root that lists one <url> entry per canonical, indexable page, each with a full <loc> and, ideally, an accurate <lastmod>. You then publish it at a stable URL, validate it, reference it in robots.txt and submit it in Google Search Console.

Short answer: Most sites should let their CMS or SEO plugin generate the sitemap, then check what it actually lists. Keep each file under 50,000 URLs and 50 MB uncompressed, as the sitemaps.org protocol requires, and split anything bigger into several sitemaps listed in a sitemap index. Include only final URLs that return 200 and are not noindexed, add a Sitemap: line to robots.txt, and submit the file in the Sitemaps report in Search Console. A sitemap helps discovery; it does not guarantee crawling or indexing.

Before you submit anything, run the file through our free XML Sitemap Validator. It checks the XML, the root element and namespace, the size limits and every <loc> and <lastmod>, then requests up to eight of the listed URLs to catch redirects, errors and noindex headers. The rest of this guide explains what a correct sitemap looks like and why each of those checks matters.

What is an XML sitemap, and do you need one?

An XML sitemap is a machine-readable list of the URLs you want search engines to know about. The format is defined by the sitemaps.org protocol, which Google, Bing and other engines support. Google’s documentation describes sitemaps as most useful for large sites, where some pages may not be linked from any other, for new sites with few external links, and for sites with a lot of video, images or news content. A small, well-linked site may be crawled fine without one, but a sitemap costs little.

It is worth being clear about the limits. A sitemap is a hint about discovery. It does not make a page indexable, override a noindex or a canonical pointing elsewhere, or compensate for a page nothing links to. Our guide to pages missing from the sitemap covers how discovery, crawling and indexing differ, and why internal links still do most of the work.

What should an XML sitemap include and exclude?

The single most useful rule: list the URL you would want to appear in search results, exactly as you would want it to appear. In practice that means:

  • Include canonical URLs that return HTTP 200, are not noindexed and are not blocked by robots.txt.
  • Include the preferred version only: https rather than http, one hostname (www or not), one trailing-slash convention.
  • Exclude URLs that redirect. List the destination instead.
  • Exclude pages carrying a noindex in a meta robots tag or an X-Robots-Tag header. Listing them sends two opposite signals.
  • Exclude URLs whose canonical points to a different page, such as filtered, sorted or tracking-parameter variants.
  • Exclude 404 and 410 pages, internal search results, cart, checkout and account pages, and staging or test URLs.

The robots.txt point catches people out. If a URL is listed in the sitemap but disallowed in robots.txt, search engines are told to find it and forbidden to fetch it. Check a sample of listed URLs in the robots.txt tester whenever you change either file.

XML sitemap format: a worked example

Here is an illustrative sitemap for a fictional shop at example.com. It contains the minimum a valid file needs, plus <lastmod>:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://www.example.com/</loc>
    <lastmod>2026-11-02</lastmod>
  </url>
  <url>
    <loc>https://www.example.com/shoes/trail-runner/</loc>
    <lastmod>2026-10-28T09:30:00+00:00</lastmod>
  </url>
  <url>
    <loc>https://www.example.com/shoes/?colour=red&amp;size=9</loc>
  </url>
</urlset>

The parts that matter:

  • The file must be UTF-8 encoded, and the <urlset> root must declare the namespace http://www.sitemaps.org/schemas/sitemap/0.9. A missing or mistyped namespace is one of the most common validation errors.
  • <loc> is the only required child of <url>. It must be an absolute URL including the protocol, and the protocol says it must be under 2,048 characters.
  • Characters with special meaning in XML must be escaped. The ampersand in the third URL is written &amp;; a bare & makes the whole file invalid, not just that entry.
  • <lastmod> uses W3C Datetime format: a date such as 2026-11-02, or a full timestamp with a time zone.

The third entry is valid but should not be there: a filtered URL like this is usually canonicalised to the main category. Validity and quality are separate questions.

How should you use lastmod?

Google’s documentation says it uses <lastmod> when the value is consistently and verifiably accurate. That qualifier is the whole point. If your generator stamps every URL with the build time, every page claims to have changed every day, and the value stops carrying any information. Set <lastmod> to the date the page’s main content last changed, not when a footer, a sidebar widget or the copyright year was updated.

Dates should never be in the future, and if thousands of URLs share one timestamp to the second, the value is generated rather than real. The protocol also defines optional <priority> and <changefreq> tags; Google’s documentation says it ignores both, so you can leave them out.

Sitemap limits: 50,000 URLs and 50 MB

The sitemaps.org protocol limits each sitemap file to 50,000 URLs and 50 MB uncompressed, and Google’s documentation gives the same limits. You may serve the file gzip-compressed to save bandwidth, but the 50 MB limit applies to the uncompressed size. Whichever limit you hit first, the answer is the same: split the URLs across several sitemaps and list them in a sitemap index.

How do sitemap index files work?

A sitemap index is a sitemap of sitemaps. It uses a <sitemapindex> root with the same namespace, and each <sitemap> entry points to one child file:

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>https://www.example.com/sitemaps/products-1.xml</loc>
    <lastmod>2026-11-03</lastmod>
  </sitemap>
  <sitemap>
    <loc>https://www.example.com/sitemaps/products-2.xml</loc>
    <lastmod>2026-11-01</lastmod>
  </sitemap>
  <sitemap>
    <loc>https://www.example.com/sitemaps/blog.xml</loc>
    <lastmod>2026-10-30</lastmod>
  </sitemap>
</sitemapindex>

The same limits apply to the index itself: up to 50,000 child sitemaps and 50 MB uncompressed. An index lists sitemap files, not pages and not other index files. Here <lastmod> refers to when the child file last changed.

Splitting by section has a side benefit: Search Console reports each child file separately, so a problem in one section is not buried in one large total.

Where should the sitemap live?

Put it at the root of the host, such as https://www.example.com/sitemap.xml or /sitemap_index.xml. The sitemaps.org protocol says a sitemap applies only to URLs at or below its own directory, so a file at /blog/sitemap.xml should not list /shop/ URLs. It should also list only URLs on its own host: a sitemap on www.example.com should not contain shop.example.com URLs unless you have verified cross-site submission. The simplest arrangement is one sitemap or index per host.

Most platforms already generate a sitemap. WordPress has produced a core sitemap at /wp-sitemap.xml since version 5.5, and most SEO plugins replace it with their own index. After switching plugins it is common to find two or three sitemaps live at once. Pick one, point robots.txt and Search Console at it, and retire the others.

How to create and validate an XML sitemap, step by step

  1. Decide which URLs belong. Start from your list of canonical, indexable templates: home, categories, products, articles, key landing pages.
  2. Generate the file. Use your CMS or SEO plugin where possible, because it updates as pages are published and deleted. For a static or custom site, generate it from your database or build process rather than by hand, so it cannot drift out of date.
  3. Split if needed. If any file approaches 50,000 URLs or 50 MB uncompressed, break it up by section or date and publish a sitemap index.
  4. Publish it at a stable URL. The file should return HTTP 200 directly, ideally without redirects, and should not sit behind a login or a bot challenge.
  5. Validate it. Enter the sitemap URL, or just the domain, in the XML Sitemap Validator. Given a domain, it reads the first Sitemap: line in robots.txt, then tries /sitemap_index.xml, /sitemap.xml and /wp-sitemap.xml. It follows up to three redirects, reads up to 10 MB including gzip, and scores the file out of 100, losing 20 points per error and 8 per warning.
  6. Fix what the spot check finds. If a sampled URL redirects, list its destination instead; if it errors or sends a noindex header, remove it, then fix whatever setting added it, so it does not come back on the next rebuild.
  7. Validate each child sitemap. For an index, the validator checks the index and the status of the child files, not the page URLs inside them. Run each child sitemap URL through it separately.
  8. Reference it in robots.txt and submit it in Search Console, as described below.

Be precise about what a clean result means. The validator checks the format of every entry but requests only up to eight URLs per run, and it reads their HTTP response, not their HTML. A noindex in a meta robots tag, or a canonical pointing elsewhere, will not show up. For pages you are unsure about, check the page itself.

How do you reference a sitemap in robots.txt?

Add a Sitemap: line with the full, absolute URL. It can go anywhere in the file, is not tied to any User-agent group, and you can include more than one:

User-agent: *
Disallow: /checkout/

Sitemap: https://www.example.com/sitemap_index.xml

Use the absolute URL, not a relative path such as /sitemap.xml. This line lets other search engines and tools find your sitemap without being told. If you list an index, you need not list each child file.

How do you submit a sitemap in Google Search Console?

  1. Open the property for the site in Search Console. A domain property or a URL-prefix property that covers the sitemap’s location both work.
  2. Go to Indexing, then Sitemaps.
  3. Enter the sitemap or index URL in the Add a new sitemap field and select Submit.
  4. Check the status. Success means Google could read the file; Has errors or Couldn’t fetch means it could not, or could only partly, process it. Select the sitemap to see details.

Submitting once is enough; Google refetches known sitemaps on its own schedule. Google also retired its sitemap ping endpoint in 2023, so scripts that pinged a URL after each update no longer do anything there. A consistently accurate <lastmod> is the signal that something has changed. For Bing, submit the same URL in Bing Webmaster Tools, or rely on the robots.txt line.

A successful status confirms the file was processed. It says nothing about whether the listed URLs were indexed. For that, use the Page indexing report, which you can filter to the URLs in a submitted sitemap.

Common XML sitemap errors and how to fix them

ProblemWhat causes itFix
File is not valid XMLA bare & in a URL, or a blank line or plugin notice printed before <?xmlEscape special characters; remove any output before the XML declaration
Wrong or missing namespaceHand-written or custom-generated filesDeclare http://www.sitemaps.org/schemas/sitemap/0.9 on the root element
Redirected URLs listedPages moved, or http:// and non-preferred host versions listedList the final destination URL that returns 200
Noindexed URLs listedThe generator ignores page-level noindex settingsExclude noindexed pages at the generator level
Every lastmod is todayBuild or cache time used instead of content change dateUse the date the main content last changed

Redirected URLs deserve particular attention on large sites, because each one makes crawlers spend a request on a URL you do not want indexed. Our article on redirect chains and crawl budget explains why that adds up, and the guide to X-Robots-Tag and noindex shows how to check which indexing instruction a page is really sending.

A short sitemap checklist

  • The sitemap returns 200 at a stable URL on the host it describes.
  • It is valid UTF-8 XML with the sitemaps.org 0.9 namespace.
  • Every <loc> is an absolute, canonical https:// URL that returns 200 and is not noindexed or blocked.
  • <lastmod> reflects real content changes, in W3C Datetime format.
  • robots.txt has a full-URL Sitemap: line, and Search Console shows Success.

Re-run the sitemap validator after any CMS, plugin or URL-structure change, since those are when stray URLs tend to appear. If you would like a second pair of eyes on how your sitemaps are generated, that is part of our technical SEO work. For how sitemaps fit with robots.txt, canonicals and internal linking, see the technical SEO guide.

How do I create an XML sitemap?

Let your CMS or SEO plugin generate it where possible, so it stays current. For a custom site, generate it from your database or build process. The file needs a urlset root with the sitemaps.org 0.9 namespace and one url entry per canonical page, each with a full loc and ideally an accurate lastmod. Then validate it, add it to robots.txt and submit it in Search Console.

How many URLs can an XML sitemap contain?

The sitemaps.org protocol allows up to 50,000 URLs and 50 MB uncompressed per sitemap file, and Google’s documentation gives the same limits. If you need more, split the URLs across several sitemaps and list them in a sitemap index.

What should not be in an XML sitemap?

Leave out URLs that redirect, return errors, carry a noindex, are blocked by robots.txt or canonicalise to a different page. Internal search results, cart and account pages, filtered or tracking-parameter variants and staging URLs also do not belong.

Does Google use lastmod, priority and changefreq?

Google’s documentation says it ignores priority and changefreq. It uses lastmod when the value is consistently and verifiably accurate, so set it to the date the page’s main content last changed, not the build time.

Do I need to add my sitemap to robots.txt if I submit it in Search Console?

It is not required for Google, but it is worth doing. The Sitemap line lets other search engines and tools find the file without being told. Use the full absolute URL; the line can appear anywhere in robots.txt.

Does submitting a sitemap guarantee my pages will be indexed?

No. A sitemap helps search engines discover URLs, but each page is still crawled and evaluated on its own. A Success status in Search Console means the file was read, not that its URLs were indexed. Check the Page indexing report for that.

Keep reading

All SEO articles

Want this applied to your site?

A free 30-minute call with Sakshi Kumari or Ashish Khan, the specialists who run MoxSEO. Bring your site and your numbers; they will tell you what to fix first and what the data cannot tell you.

A call is not an engagement. SEO plans start at $584 a month, and we never guarantee rankings.

How the call works

  1. Send your siteBook a slot and tell us which SEO questions you want answered for your site.
  2. We review it firstBefore the call we look at crawl health, indexation and AI citation coverage on your pages.
  3. Thirty minutes, ranked fixesYou leave knowing what to fix first and why. No proposal unless you ask for one.