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 eliminates guesswork from Google's crawl discovery process. Done wrong — wrong format, wrong content, stale dates — 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 is most valuable when you have pages that are poorly linked internally, a new site that search engines have not yet crawled thoroughly, 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://orhttp://) - 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:
&→&,<→<,>→>,"→",'→'
Step 2: Choose a Generation Method
For most sites, do not write sitemaps by hand. The exception is a very small site (under 20 pages) where manual maintenance is feasible.
Framework or CMS plugins (recommended):
- WordPress: Yoast SEO or Rank Math automatically generate and update sitemaps at
/sitemap_index.xml - Next.js:
next-sitemapnpm package generates static sitemaps during build; Next.js 13.3+ has built-in sitemap support viaapp/sitemap.ts - Shopify: auto-generates at
/sitemap.xml— no configuration needed - Hugo: built-in sitemap generation with the
--themeflag
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 ensures <lastmod> dates are always 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 — Google will discover and process all the referenced sitemaps automatically.
Step 5: Submit to Google Search Console and Bing Webmaster Tools
Google Search Console:
- Go to Google Search Console and select your property
- Navigate to Indexing → Sitemaps in the left menu
- In the "Add a new sitemap" field, enter your sitemap path (e.g.,
sitemap.xml) - Click Submit
- The status column will show: Pending → Success (with URL count) or Has errors (with details)
Bing Webmaster Tools:
- Log into Bing Webmaster Tools
- Select your site and go to Sitemaps
- Click Submit sitemap and enter the full sitemap URL
- 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 — 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: 26/06/2026, June 26 2026, 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 should not 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), be 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 is 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 is not 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 — pages with recent <lastmod> dates receive crawl priority. Pages excluded from the sitemap are 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 improve how quickly new and updated content gets indexed.
Use the Sitemap Validator to verify your sitemap against the protocol spec before submission.