HomeArticlesHow ToCreate a sitemap.xml
HOW TO

How to Create a sitemap.xml

Learn how to create and submit a sitemap.xml file — with the correct XML format, priority and changefreq tags, image sitemaps, and Search Console submission.

Reviewed by the thecalcu.com team · Last updated August 4, 2026

Free calculators used in this guide

Sitemap.xml GeneratorSitemap Validator

A sitemap.xml file is the most direct way to tell search engines which pages on your site exist, which ones matter, and when they were last updated. Done right, it takes the guesswork out of Google's crawl discovery process. Get the format wrong, the content wrong, or leave the dates stale, and it actively misleads crawlers and wastes crawl budget. This guide walks through creating a correct, production-ready sitemap from scratch.

Overview

The Sitemaps protocol was jointly developed by Google, Yahoo, and Microsoft in 2006 and is now maintained at sitemaps.org. It defines an XML format that any web crawler can consume to discover URLs and metadata about pages on a domain.

A sitemap earns its keep most when you have pages that are poorly linked internally, a new site that search engines haven't crawled thoroughly yet, or more than a few hundred pages that need consistent indexing. Use the Sitemap Generator to create a sitemap automatically, and the Sitemap Validator to check an existing one.

What You Need

  • A list of all the URLs you want indexed (your canonical, indexable pages only)
  • Last-modification dates for those pages (from your CMS or deployment system)
  • FTP/SFTP access or a deployment workflow to place the sitemap at your domain root
  • A Google Search Console account to submit and monitor the sitemap

Step 1: Understand the sitemap.xml Format

A sitemap is a valid XML file using the http://www.sitemaps.org/schemas/sitemap/0.9 namespace. The structure is:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <url>
    <loc>https://example.com/</loc>
    <lastmod>2026-06-26</lastmod>
    <changefreq>monthly</changefreq>
    <priority>1.0</priority>
  </url>
</urlset>

The four URL-level tags:

Tag Required Description
<loc> Yes The full URL, including https:// and trailing slash if used
<lastmod> No Date page was last modified (W3C Datetime: YYYY-MM-DD)
<changefreq> No Hint for crawl frequency (Google largely ignores this)
<priority> No Relative priority 0.0-1.0 (Google largely ignores this)

Critical rules:

  • All URLs must begin with the protocol (https:// or http://)
  • URLs must be consistently formatted. If your site uses trailing slashes, every <loc> must have one.
  • The <loc> URL must match the canonical version of the page exactly
  • Special characters in URLs must be XML-escaped: &&amp;, <&lt;, >&gt;, "&quot;, '&apos;

Step 2: Choose a Generation Method

For most sites, don't write sitemaps by hand. The exception is a very small site (under 20 pages) where manual maintenance is realistic.

Framework or CMS plugins (recommended):

  • WordPress: Yoast SEO or Rank Math automatically generate and update sitemaps at /sitemap_index.xml
  • Next.js: next-sitemap npm package generates static sitemaps during build; Next.js 13.3+ has built-in sitemap support via app/sitemap.ts
  • Shopify: auto-generates at /sitemap.xml, no configuration needed
  • Hugo: built-in sitemap generation with the --theme flag

Online generators: Use the Sitemap Generator for small to medium static sites. Enter your domain, crawl depth, and any URL patterns to exclude.

Dynamic server-side generation: For large sites or sites where content changes frequently, generate sitemaps programmatically, either on every request (with caching) or as a build step that runs on content publish. Dynamic generation keeps <lastmod> dates accurate.

Manual creation: Appropriate only for sites under 20 pages. Create a text file, save it as sitemap.xml, and edit it each time pages are added or changed.

Step 3: Write the XML Structure

A complete sitemap example with multiple URL types and all optional tags:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

  <!-- Homepage: highest priority -->
  <url>
    <loc>https://example.com/</loc>
    <lastmod>2026-06-26</lastmod>
    <changefreq>weekly</changefreq>
    <priority>1.0</priority>
  </url>

  <!-- Main product page -->
  <url>
    <loc>https://example.com/products/</loc>
    <lastmod>2026-06-20</lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.9</priority>
  </url>

  <!-- Individual product -->
  <url>
    <loc>https://example.com/products/widget-pro/</loc>
    <lastmod>2026-05-15</lastmod>
    <changefreq>monthly</changefreq>
    <priority>0.8</priority>
  </url>

  <!-- Blog post -->
  <url>
    <loc>https://example.com/blog/getting-started-guide/</loc>
    <lastmod>2026-04-10</lastmod>
    <changefreq>yearly</changefreq>
    <priority>0.6</priority>
  </url>

  <!-- Contact page: lower priority, rarely changes -->
  <url>
    <loc>https://example.com/contact/</loc>
    <lastmod>2025-11-01</lastmod>
    <changefreq>yearly</changefreq>
    <priority>0.3</priority>
  </url>

</urlset>

Priority guidelines (these are relative signals within your own site, not comparisons to other sites):

  • 1.0: Homepage, most important category pages
  • 0.8-0.9: Core content pages, important product pages
  • 0.6-0.7: Blog posts, articles, individual product pages
  • 0.3-0.5: Tag pages, author pages, less important static pages
  • 0.0-0.2: Rarely-updated utility pages (about, legal, contact)

Step 4: Add Image and Video Sitemaps

For media-heavy sites, extend your sitemap with image or video metadata so search engines can index your media content.

Image sitemap extension:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:image="http://www.google.com/schemas/sitemap-image/1.1">
  <url>
    <loc>https://example.com/gallery/mountain-collection/</loc>
    <image:image>
      <image:loc>https://example.com/images/mountain-peak.jpg</image:loc>
      <image:title>Snow-capped Mountain Peak at Sunrise</image:title>
      <image:caption>Photograph taken at 4,200m altitude in the Himalayas</image:caption>
    </image:image>
    <image:image>
      <image:loc>https://example.com/images/valley-view.jpg</image:loc>
      <image:title>Valley View from Base Camp</image:title>
    </image:image>
  </url>
</urlset>

Video sitemap extension:

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
  <url>
    <loc>https://example.com/tutorials/calculator-guide/</loc>
    <video:video>
      <video:thumbnail_loc>https://example.com/thumbs/calc-guide.jpg</video:thumbnail_loc>
      <video:title>How to Use the SIP Calculator</video:title>
      <video:description>Step-by-step walkthrough of calculating SIP returns over 20 years.</video:description>
      <video:content_loc>https://example.com/videos/calc-guide.mp4</video:content_loc>
      <video:duration>312</video:duration>
    </video:video>
  </url>
</urlset>

Sitemap index for large sites (50,000+ URLs):

<?xml version="1.0" encoding="UTF-8"?>
<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
    <loc>https://example.com/sitemap-pages.xml</loc>
    <lastmod>2026-06-26</lastmod>
  </sitemap>
  <sitemap>
    <loc>https://example.com/sitemap-products.xml</loc>
    <lastmod>2026-06-25</lastmod>
  </sitemap>
  <sitemap>
    <loc>https://example.com/sitemap-blog.xml</loc>
    <lastmod>2026-06-26</lastmod>
  </sitemap>
</sitemapindex>

Submit the sitemap index URL to Search Console, and Google will discover and process all the referenced sitemaps automatically.

Step 5: Submit to Google Search Console and Bing Webmaster Tools

Google Search Console:

  1. Go to Google Search Console and select your property
  2. Navigate to Indexing → Sitemaps in the left menu
  3. In the "Add a new sitemap" field, enter your sitemap path (e.g., sitemap.xml)
  4. Click Submit
  5. The status column will show: Pending → Success (with URL count) or Has errors (with details)

Bing Webmaster Tools:

  1. Log into Bing Webmaster Tools
  2. Select your site and go to Sitemaps
  3. Click Submit sitemap and enter the full sitemap URL
  4. Bing processes the submission within 24-48 hours

Add Sitemap directive to robots.txt:

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

This passively notifies any crawler that discovers your robots.txt file about your sitemap, with no manual submission required for them.

Common Mistakes to Avoid

Wrong Content-Type header. Your sitemap must be served with Content-Type: application/xml or Content-Type: text/xml. Servers that serve XML files as text/plain or application/octet-stream will cause parsing failures in some crawlers. Check with curl -I https://example.com/sitemap.xml and inspect the Content-Type header.

Incorrect date format for <lastmod>. The Sitemaps protocol requires W3C Datetime format, YYYY-MM-DD or YYYY-MM-DDThh:mm:ssZ. Common wrong formats include 26/06/2026, June 26 2026, and Unix timestamps (1751000000). These cause validation failures. Google also recommends only updating <lastmod> when content genuinely changes; updating it artificially on every crawl trains Google to ignore it entirely.

Including noindex pages in your sitemap. Pages with <meta name="robots" content="noindex"> or a noindex response header shouldn't appear in your sitemap. Including them sends contradictory signals. Audit your sitemap against your noindex pages before submitting.

Incorrect URL format (missing protocol, inconsistent trailing slashes). Every <loc> must be the full canonical URL including https://. If your site uses trailing slashes (https://example.com/about/), every sitemap entry must include them. If you use no trailing slashes (https://example.com/about), stay consistent. Mixing these within a sitemap can cause Google to treat the same page as two different URLs.

Not updating sitemap after publishing new content. A sitemap submitted once and never updated becomes progressively less useful. New pages not in the sitemap rely on link discovery alone. Automate sitemap regeneration as part of your content publish workflow, or schedule regular regeneration if automation isn't feasible.

Formula & Methodology

The Sitemaps protocol is defined at sitemaps.org and built on standard XML. The complete formal structure:

sitemap.xml
├── XML declaration: <?xml version="1.0" encoding="UTF-8"?>
├── Root element: <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
│   └── For each URL: <url>
│       ├── <loc>       Required. Full URL. Max 2,048 characters.
│       ├── <lastmod>   Optional. W3C Datetime.
│       ├── <changefreq> Optional. always|hourly|daily|weekly|monthly|yearly|never
│       └── <priority>  Optional. 0.0 to 1.0 (default: 0.5)

File size constraints:

  • Maximum 50,000 URLs per sitemap file
  • Maximum 50MB per sitemap file (uncompressed)
  • Gzip compression is accepted and recommended: a 50MB sitemap compresses to roughly 5-10MB
  • Sitemap index files follow the same limits: max 50,000 sitemap references, max 50MB

Crawl budget implications: A clean sitemap with accurate <lastmod> dates helps Google allocate crawl budget efficiently, since pages with recent <lastmod> dates get crawl priority. Pages excluded from the sitemap get crawled based on link signals alone. For sites over 10,000 pages, carefully curating what appears in the sitemap (excluding low-value pages, near-duplicates, and thin content) can meaningfully speed up how quickly new and updated content gets indexed.

Use the Sitemap Validator to verify your sitemap against the protocol spec before submission.

Frequently Asked Questions

What is a sitemap.xml and why does my website need one?
A sitemap.xml is an XML file that lists the URLs on your website along with optional metadata about each page: when it was last updated, how often it changes, and its relative priority. Search engines like Google and Bing use sitemaps to discover and crawl pages more efficiently, particularly pages that may not be well-linked from elsewhere on the site. Google can find your pages without a sitemap through link discovery, but a sitemap guarantees that important pages get submitted for crawling, which matters especially on new sites, large sites, or sites with pages that aren't heavily interlinked.
What is the maximum number of URLs allowed in a sitemap.xml file?
A single sitemap file can contain a maximum of 50,000 URLs and must not exceed 50MB when uncompressed. These limits come from the Sitemaps protocol at sitemaps.org. If your site has more than 50,000 URLs, split your content across multiple sitemap files and create a sitemap index file that lists all of them. The sitemap index file itself can reference up to 50,000 individual sitemap files, allowing a maximum of 2.5 billion URLs per index, well above any realistic website size.
Which tags in sitemap.xml are required and which are optional?
Only the <loc> tag (the URL) is required within each <url> entry. The <lastmod>, <changefreq>, and <priority> tags are all optional. The enclosing <urlset> root element is required, and each URL must be wrapped in a <url> element. The XML declaration at the top (<?xml version='1.0' encoding='UTF-8'?>) and the XML namespace on <urlset> are required for the file to validate correctly. Google has stated publicly that it largely ignores <changefreq> and <priority> values when deciding crawl behaviour.
What format must the lastmod date use in sitemap.xml?
The <lastmod> value must follow W3C Datetime format as specified in the Sitemaps protocol. Accepted formats are YYYY-MM-DD (e.g., 2026-06-26), YYYY-MM-DDThh:mm:ss+00:00, or YYYY-MM-DDThh:mm:ssZ (both include time and timezone). The most common format used in static sitemaps is YYYY-MM-DD. Using incorrect date formats, like DD/MM/YYYY or Unix timestamps, causes validation errors. Google recommends only updating <lastmod> when the page content actually changes; updating it artificially on every crawl trains Google to distrust it.
What is a sitemap index file and when do I need one?
A sitemap index file is a special XML file that lists multiple sitemap files rather than individual URLs. You need one when your site exceeds 50,000 URLs (the per-sitemap limit), when you want to organise sitemaps by content type (posts, products, images, videos), or when your CMS generates separate sitemaps for different sections. It uses <sitemapindex> as the root element instead of <urlset>, and contains <sitemap> entries, each with a <loc> pointing to an individual sitemap file and an optional <lastmod>. The index file itself must also stay under 50MB and 50,000 entries.
Should I include noindex pages in my sitemap.xml?
No. Including a noindex page in your sitemap sends a contradictory signal to Google: you're asking it to index the page by including it in the sitemap, and telling it not to via the noindex tag. Google's guidelines explicitly say not to include noindex-marked pages in your sitemap. Also exclude pages that redirect (301 or 302), pages blocked by robots.txt, error pages (404, 500), duplicate pages (canonicalise instead), and session-ID or filter URLs that produce near-duplicate content.
How do I submit my sitemap to Google Search Console?
Log into Google Search Console, select your property, and go to Indexing → Sitemaps in the left sidebar. Enter the URL of your sitemap (e.g., https://example.com/sitemap.xml) and click Submit. Google will fetch and parse the sitemap and show you a status (Success, Has errors, etc.) along with how many URLs were discovered. Resubmit whenever you make significant changes, though Google also recrawls sitemaps periodically on its own. It's worth adding a Sitemap: directive to your robots.txt file too, for passive discovery by all crawlers.
What is the difference between priority and changefreq in sitemap.xml?
The <priority> tag (values 0.0 to 1.0) and <changefreq> tag (always, hourly, daily, weekly, monthly, yearly, never) were originally meant to signal crawl priority and frequency to search engines. In practice, Google has publicly stated that it largely ignores both fields when making crawl decisions, relying on its own signals to determine how often to crawl and which pages to prioritise. Bing gives them minimal weight too. Include them for completeness, but don't count on them to change crawl behaviour. The <loc> and <lastmod> tags matter far more.
Can I use a sitemap.xml for image and video content?
You can. The Sitemaps protocol includes extensions for images and videos. For images, add an <image:image> element inside each <url> entry containing <image:loc> (the image URL) and optionally <image:title>, <image:caption>, and <image:geo_location>. For videos, use <video:video> with <video:thumbnail_loc>, <video:title>, <video:description>, and <video:content_loc>. These extensions help search engines discover media that may not be crawlable through HTML links alone, and they're particularly valuable for image-heavy sites like portfolios, e-commerce, and news publishers. Use the correct XML namespace declarations for each extension.
Do I need a sitemap.xml if my site has fewer than 500 pages?
For small, well-linked sites with fewer than 500 pages, a sitemap is less critical but still worth having as a best practice. It takes minutes to generate and gives you a clear record of which URLs you consider canonical and indexable. Sitemaps become more valuable as site size grows, when pages have few internal links pointing to them, when you publish new content frequently (news, blog), or when you've recently launched and aren't yet well-indexed. There's no downside to having a valid sitemap, and Google recommends it for sites of any size.
What Content-Type header should my sitemap.xml return?
Your sitemap.xml should be served with a Content-Type header of application/xml or text/xml. Most web servers automatically assign the correct MIME type for .xml files, but misconfigured servers sometimes serve them as text/plain or application/octet-stream, which causes parsing failures in some crawlers. If you're generating your sitemap dynamically, say from a server-side script, explicitly set the Content-Type header in your response. Verify the header using browser developer tools (Network tab, select the sitemap request, check Response Headers) or a tool like curl -I https://example.com/sitemap.xml.
How often should I update and resubmit my sitemap?
Update your sitemap whenever your site's content changes: new pages added, pages removed, or significant content changes that update the <lastmod> date. For high-frequency publishers (daily blog posts, news sites), sitemaps should update automatically on each new publication, ideally triggered by the CMS. For mostly static sites, manual or scheduled weekly regeneration works fine. Resubmit to Google Search Console after major changes; for routine updates, adding the Sitemap: directive to robots.txt means Google picks up changes during its regular robots.txt crawl without manual resubmission.

Related Articles

GUIDE

SEO Technical Checklist — robots.txt, Sitemap & Meta Tags

HOW TO

How to Generate a UUID

HOW TO

How to Use Cron Expressions

HOW TO

How to Write a robots.txt File

COMPARISON

Regex vs String Methods — When to Use Which