XML Sitemap Guide: How to Create and Optimize Your Sitemap

An XML sitemap is one of the most fundamental tools in technical SEO. It provides search engines with a structured list of every page on your website that you want indexed, along with metadata about each page. While search engines can discover pages through crawling links, a well-optimized XML sitemap ensures that no important page is overlooked and that search engines understand your site's structure from the moment they visit.

This guide covers everything from basic sitemap creation to advanced optimization techniques that maximize your crawl efficiency and indexation coverage. Whether you are setting up your first sitemap or auditing an existing one, these practices will help search engines discover and index your content faster and more reliably.

What Is an XML Sitemap

An XML sitemap is a file written in Extensible Markup Language (XML) that lists the URLs on your website. Each URL entry can include optional metadata such as the last modification date, how frequently the page changes, and the relative priority of the page compared to other pages on your site. Search engines like Google, Bing, and others read this file to understand what pages exist on your site and when they were last updated.

The XML sitemap protocol is standardized and documented at Google's sitemaps documentation. All major search engines support it, making XML sitemaps a universal tool for improving how your content is discovered.

It is important to distinguish an XML sitemap from an HTML sitemap. An HTML sitemap is a regular web page that lists links to your content for human visitors. An XML sitemap is a machine-readable file designed exclusively for search engine crawlers. Both can be valuable, but they serve different purposes.

Why XML Sitemaps Matter for SEO

Search engines discover pages primarily through two methods: following links from page to page, and reading sitemaps. While a well-linked site can be crawled without a sitemap, there are several situations where an XML sitemap provides critical benefits.

New Websites and Pages

New websites have few or no inbound links, which means search engines may not discover them quickly through link-based crawling. A submitted XML sitemap tells Google and Bing about your pages directly, accelerating the initial indexation process. Similarly, new pages on an existing site may not be linked from high-traffic pages immediately. The sitemap ensures they are discovered regardless of internal linking.

Large Websites

Sites with thousands or millions of pages face crawl budget limitations. Search engines allocate finite crawling resources to each site, and not every page will be crawled on every visit. An XML sitemap with accurate lastmod dates helps search engines prioritize which pages to crawl first, ensuring recently updated content gets indexed quickly.

Isolated or Poorly Linked Pages

Pages that are not well connected through internal links may be difficult for crawlers to discover. Archive pages, tag pages, and deep content that is only reachable through many navigation clicks benefit from sitemap inclusion. While improving your internal linking strategy is the better long-term solution, the sitemap provides a safety net for pages that might otherwise go unindexed.

Content Updates

When you update existing content, the lastmod tag in your sitemap signals to search engines that the page has changed and should be recrawled. This is particularly valuable for content refresh strategies where you update published articles to keep them current. Without accurate lastmod dates, search engines may not prioritize recrawling updated pages.

XML Sitemap Structure and Syntax

Understanding the XML sitemap format helps you validate your sitemap and troubleshoot issues. A basic XML sitemap follows a strict structure.

Required Elements

Every XML sitemap must begin with an XML declaration and include the <urlset> root element with the proper namespace. Each page is represented by a <url> element containing at minimum a <loc> element with the full URL of the page.

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://www.example.com/page</loc>
    <lastmod>2026-02-11</lastmod>
  </url>
</urlset>

Optional Elements

Each URL entry supports three optional elements:

  • <lastmod>: The date the page was last modified, in W3C Datetime format (YYYY-MM-DD). Google uses this value to decide which pages to recrawl. Only update this date when the page content actually changes.
  • <changefreq>: How frequently the page is expected to change (always, hourly, daily, weekly, monthly, yearly, never). Google has confirmed it largely ignores this element, so it is optional and not impactful.
  • <priority>: A value between 0.0 and 1.0 indicating the relative importance of a page compared to other pages on your site. Google also largely ignores this element. It has no effect on how your pages are ranked in search results.

Of these three optional elements, lastmod is the only one with practical SEO value. Focus your efforts on maintaining accurate last modification dates rather than tweaking changefreq or priority values.

Sitemap Index Files

When your site has more than 50,000 URLs or your sitemap file exceeds 50 MB, you need to split it into multiple sitemap files. A sitemap index file references these individual sitemaps:

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>https://www.example.com/sitemap-posts.xml</loc>
    <lastmod>2026-02-11</lastmod>
  </sitemap>
  <sitemap>
    <loc>https://www.example.com/sitemap-pages.xml</loc>
    <lastmod>2026-01-30</lastmod>
  </sitemap>
</sitemapindex>

Organize your sitemap files logically. Grouping by content type (posts, pages, products, categories) makes it easier to identify indexation problems for specific sections of your site when reviewing Search Console data.

Creating Your XML Sitemap

The method you use to create your XML sitemap depends on your website platform and the level of control you need.

CMS Plugins and Built-In Features

Most content management systems include sitemap generation either natively or through plugins. WordPress sites commonly use Yoast SEO, Rank Math, or the built-in WordPress sitemap feature. Shopify, Squarespace, and Wix generate sitemaps automatically. These solutions handle URL discovery, lastmod updates, and sitemap index creation without manual effort.

When using a CMS plugin, verify that the generated sitemap meets the quality criteria described in the optimization section below. Automatic generation does not guarantee optimal configuration.

Static Site Generators

For sites built with static generators like Next.js, Gatsby, Hugo, or Eleventy, sitemap generation is typically handled at build time. Configure your build process to include only published pages, set accurate dates based on file modification times or front matter metadata, and output the sitemap to your public directory where search engines can find it.

Manual Creation

Small websites with a stable page structure can use manually created sitemaps. Write the XML file following the structure described above, and update it whenever you add or remove pages. This approach gives you complete control but requires discipline to keep the sitemap current. For sites with more than a few dozen pages, automated generation is strongly recommended.

Crawl-Based Generation

Tools like Screaming Frog, Sitebulb, and various online generators can crawl your site and produce an XML sitemap from the discovered pages. This approach is useful for creating an initial sitemap or auditing what a crawler can discover. However, crawl-based sitemaps are snapshots in time and must be regenerated regularly to stay current.

Audit Your XML Sitemap

Elvisto validates your sitemap structure, checks for errors, and identifies pages that should or should not be included.

Run a Free Sitemap Audit

Optimizing Your XML Sitemap

A well-optimized XML sitemap contains only the pages you want indexed, uses accurate metadata, and avoids common problems that confuse search engines.

Include Only Indexable Pages

Your sitemap should only contain URLs that meet all of the following criteria:

  • Return a 200 HTTP status code
  • Do not have a noindex meta tag or X-Robots-Tag header
  • Do not redirect to another URL
  • Are the canonical version of the page (the canonical tag points to itself)
  • Are not blocked by robots.txt
  • Contain substantive, valuable content

Including non-indexable pages in your sitemap creates mixed signals. If your sitemap says a page should be indexed but the page itself says noindex, Google must resolve the conflict. Keeping your sitemap clean eliminates this confusion and signals that you have a well-maintained site.

Use Accurate Lastmod Dates

The lastmod date should reflect when the page content was genuinely updated, not when the page was regenerated or when the server timestamp changed. Setting all lastmod dates to today's date is counterproductive because it tells search engines that every page was just updated, which is clearly false and will be ignored.

Implement lastmod tracking at the content level. When a blog post is edited, update its lastmod date. When a product price changes, update the product page's lastmod date. When the site template changes without affecting page content, do not update lastmod dates across all pages.

Match Your Sitemap to Your Canonical URLs

Every URL in your sitemap should be the exact canonical URL of that page. Use consistent protocols (https, not http), consistent www preferences, and consistent trailing slash usage. If your canonical URL is https://www.example.com/page/, then that exact URL should appear in your sitemap, not https://example.com/page or https://www.example.com/page without the trailing slash.

Keep Sitemaps Under the Limits

Each sitemap file must contain no more than 50,000 URLs and must not exceed 50 MB uncompressed. In practice, keeping individual sitemaps well below these limits makes them easier to manage and debug. Aim for 10,000 to 25,000 URLs per sitemap file. Use Gzip compression on sitemap files to reduce bandwidth without affecting the URL limit.

Submitting Your Sitemap to Search Engines

Creating a sitemap is not enough. You must also tell search engines where to find it. There are three methods, and using all three provides the best coverage.

Google Search Console

Submit your sitemap URL in the Sitemaps section of Google Search Console. After submission, Google reports the number of URLs discovered, how many were successfully indexed, and any errors encountered. Check this report regularly to catch problems early. If you use a sitemap index, submit the index URL rather than each individual sitemap file.

Bing Webmaster Tools

Bing has its own webmaster tools with a sitemap submission feature. The process is similar to Google Search Console. Submit your sitemap URL and monitor the indexation reports for errors. Bing's search share is smaller than Google's, but it serves millions of users and should not be ignored.

Robots.txt Reference

Add a Sitemap directive to your robots.txt file pointing to your sitemap URL:

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

This method ensures that any search engine crawler that reads your robots.txt file discovers your sitemap, even if you have not manually submitted it through a webmaster tools interface. Place the Sitemap directive at the bottom of your robots.txt file.

Common XML Sitemap Mistakes

These mistakes are found on a significant percentage of the websites audited with Elvisto. Correcting them improves how efficiently search engines process your site.

Including Non-200 URLs

Sitemaps that contain URLs returning 301, 302, 404, or 500 status codes waste crawl budget and signal poor site maintenance. Regularly validate your sitemap URLs by crawling them and removing any that do not return a clean 200 response. Automate this check as part of your technical SEO audit process.

Stale Sitemaps

A sitemap that has not been updated in months tells search engines nothing useful about what has changed on your site. If your CMS or build process does not update the sitemap automatically when content changes, set up a scheduled task or workflow to regenerate it regularly. Stale lastmod dates are worse than no lastmod dates because they actively mislead crawlers.

Including Noindexed or Canonicalized Pages

Pages with noindex directives or canonical tags pointing to different URLs should never appear in your sitemap. Including them creates a contradiction: the sitemap says "index this page" while the page itself says "do not index this page" or "the canonical version is elsewhere." Remove these conflicting URLs from your sitemap to send clear, consistent signals.

Mismatched Protocols and URL Formats

Using HTTP URLs in a sitemap when your site redirects to HTTPS, or using non-www URLs when your canonical format includes www, causes crawl inefficiency. Crawlers fetch the sitemap URL, get redirected, and then have to process the redirect before accessing the actual content. Ensure every URL in your sitemap matches the exact format of the canonical URL.

Missing Sitemap Reference in Robots.txt

Many sites create a perfectly valid sitemap but forget to reference it in their robots.txt file. While submitting through Search Console is sufficient for Google, adding the robots.txt reference ensures all search engine crawlers can discover your sitemap automatically.

Key Takeaway

An XML sitemap is not a set-and-forget file. Maintain it as a living document that accurately reflects your site's indexable pages. Include only 200-status canonical URLs, use accurate lastmod dates, submit through Search Console, and reference it in robots.txt. Regular validation prevents the common mistakes that undermine its effectiveness.

Frequently Asked Questions

How many URLs can an XML sitemap contain?

A single XML sitemap file can contain a maximum of 50,000 URLs and must not exceed 50 MB when uncompressed. If your site has more than 50,000 URLs, you need to split your sitemap into multiple files and reference them from a sitemap index file. There is no limit to how many sitemap files you can have in a sitemap index.

Should I include every page in my XML sitemap?

No. Only include pages that you want search engines to index. Exclude pages with noindex tags, pages that redirect to other URLs, duplicate pages with canonical tags pointing elsewhere, thin or low-value pages, and private or password-protected pages. A clean sitemap that contains only indexable, valuable pages helps search engines prioritize your important content.

Does having an XML sitemap guarantee my pages will be indexed?

No. An XML sitemap is a suggestion, not a directive. It tells search engines about pages you want indexed, but Google makes the final decision about whether to index each page based on content quality, crawl budget, and other factors. However, a well-structured sitemap significantly increases the likelihood that your pages will be discovered and indexed promptly.

How often should I update my XML sitemap?

Your XML sitemap should update automatically whenever you publish new content or remove old pages. Most CMS platforms and sitemap plugins handle this automatically. If you manage your sitemap manually, update it every time you add, remove, or significantly modify a page. The lastmod dates in your sitemap should reflect actual content changes, not arbitrary timestamps.

HP

Haresh Prajapati

Haresh Prajapati works on Elvisto, where he builds the crawler and the rule library behind the audit. He writes about technical SEO and how search engines reach, render and index a site.

Validate Your XML Sitemap Today

Elvisto checks your sitemap for errors, missing pages, and optimization opportunities in under 5 minutes.

Start Your Free Audit

No credit card required. Free plan available forever.