SEO

What Is an XML Sitemap and How Do You Create One?

Talha Aslan 18 min read 2 views

What is an XML sitemap and what does it do?

An XML sitemap is a file that lists the pages, videos and other files on your website and tells search engines where they live and when they last changed in a meaningful way. Google reads it to crawl your site more efficiently. However, it is a hint, not a command, and it never promises indexing.

We are Talha Aslan and team, a digital marketing and web team, and the sitemap is one of the first files we open in a technical SEO audit. It shows what a site says about itself. Which URLs do you consider important? What did you forget? And which pages are you promoting by mistake? In this guide we cover the definition, structure, limits, ways to create one, Search Console submission and the most common mistakes.

Every rule here comes from two primary sources: Google Search Central documentation and sitemaps.org, which defines the protocol itself. If you want the broader context first, read our overview of what technical SEO is, with ten practical tips. Here we stay focused on the sitemap.

Does an XML sitemap guarantee indexing?

No. Google's sitemap overview says it plainly: a sitemap helps search engines discover URLs on your site, but it doesn't guarantee that every item in it will be crawled and indexed. So treat the file as a strong suggestion rather than an instruction.

We stress this point because the most common question we hear is simple. "I submitted my sitemap, so why aren't my pages showing up?" Google decides whether to index a page based on many factors. These include content quality, duplication, canonical signals and technical accessibility. In short, the sitemap only speeds up the discovery step.

That said, calling a sitemap useless would also be wrong. It shortens the path to a new page that has no internal or external links yet. It also invites Google to recrawl pages you updated, as long as your lastmod values are honest. To diagnose pages that stay out of the index, use our guide on how to find unindexed pages in Search Console.

Which websites actually need a sitemap?

According to Google, a sitemap helps most in a few situations. Your site is large. Your site is new and has few external links. Or your site carries a lot of rich media such as video and images, or appears in Google News. On large sites, the crawler can miss pages that are new or recently changed.

On the other hand, Google notes that a site with about 500 pages or fewer, comprehensive internal linking and little media content may not need one. In other words, a small brochure site will survive without it. Still, we recommend one for most projects, because it costs almost nothing and gives you a handy reference list for tracking index status in Search Console.

In short, the better question is not "do I need a sitemap?" but "is my sitemap correct?" A broken file can send more confusing signals than no file at all. For example, if you list hundreds of redirected or noindexed URLs, your Search Console reports fill up with noise, and the real problems become harder to spot.

How is an XML sitemap different from an HTML sitemap?

They share a name but serve different readers. The XML version is for machines, meaning search engine crawlers. The HTML version is an ordinary web page full of links that a visitor can browse. So the table below sums up the difference.

FeatureXML sitemapHTML sitemap
AudienceSearch engine crawlersHuman visitors
FormatXML file that follows the sitemaps.org protocolRegular page with a list of links
Extra datalastmod, images, video, hreflang alternatesOnly anchor text and hierarchy
How Google finds itSearch Console and robots.txtLinked from the menu or footer
Limits50,000 URLs or 50 MB uncompressedNo protocol limit; usability decides

Today an HTML sitemap is mainly a usability and internal linking tool. On a large category structure, it helps visitors find what they want and passes links to deep pages. However, it does not replace the XML file. The two work together.

What does the structure of an XML sitemap look like?

The sitemaps.org protocol defines three required tags. There is the outer urlset wrapper, one url entry per page, and a loc tag inside each entry that holds the address. The wrapper must declare the protocol namespace. Here is the simplest possible example for example.com:

<?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-09-12</lastmod>
  </url>
  <url>
    <loc>https://www.example.com/services/web-design/</loc>
    <lastmod>2026-08-30</lastmod>
  </url>
</urlset>

Also keep a few rules in mind. First, save the file with UTF-8 encoding. Second, Google asks for fully qualified, absolute URLs, so you write the protocol and domain rather than a relative path. Third, you must escape special characters such as the ampersand as XML entities.

Per the official protocol, a loc value can hold up to 2,048 characters. The file location also sets its scope. For example, a file in the /catalog/ folder can only list URLs under that folder. That is why you usually place the main file at the site root, because a root sitemap can cover the whole site.

How should you use lastmod, changefreq and priority?

In addition, the protocol defines three optional tags: lastmod, changefreq and priority. Google's guide to building a sitemap is clear about two of them. Google ignores the priority and changefreq values. So setting every page to 1.0 or "daily" does nothing for your rankings or your crawl frequency.

lastmod is different. Google uses it if it's consistently and verifiably accurate. In practice, a date that changes when the main content of a page changes is useful. Meanwhile, a plugin that stamps today's date on every URL every night slowly turns that signal into noise, and Google learns to stop trusting it.

We cover correct lastmod usage, which edits deserve a new date and the usual mistakes in a separate article: the sitemap lastmod tag explained. We won't repeat it here. The practical rule is short. You can leave changefreq and priority in place because they do no harm, but spend your effort on keeping lastmod honest.

What are the XML sitemap size limits?

According to Google, a single sitemap can contain up to 50,000 URLs and can't exceed 50 MB uncompressed. That limit applies to every supported format: XML, RSS and plain text. Once you hit either limit, you split the file and tie the parts together with a sitemap index file.

You can serve the file compressed with gzip, and the protocol allows this. However, compression is not a way around the 50 MB limit, because the limit applies to the uncompressed size. Compression only reduces transfer time.

In practice, very few sites come close to 50,000 URLs in one file. Even so, on a large online store we recommend separate files for products, categories and blog posts. That way the Search Console report shows you which content type has a problem. For instance, if discovered pages drop in the product file while the blog file stays flat, you know where to look right away.

What is a sitemap index file, and when do you need one?

A sitemap index is a parent file that lists the addresses of other sitemaps. If you have several sitemaps, you submit the index to Search Console instead of sending each file one by one. The structure is almost identical. Only the wrapper becomes sitemapindex, and each entry becomes sitemap:

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

Google's documentation on large sitemaps says an index file may have up to 50,000 loc tags. You can also submit up to 500 sitemap index files for each site in Search Console. The sitemaps that an index references must sit in the same directory as the index or lower in the site hierarchy.

Most popular SEO plugins for WordPress already build this setup for you. You get an index at the root and separate sitemaps for posts, pages, categories and products below it. So if you use a plugin, you only need to submit the index file.

When do image, video and news sitemaps help?

The biggest advantage of the XML format is its extensions. Google supports three extensions that add data to a standard sitemap. The image extension tells Google where images live. The video extension can carry details such as running time, rating and age suitability. Finally, the news extension passes along the article title and publication date.

  • Image sitemap: Useful when your images load through JavaScript or sit somewhere the crawler can't easily find them.
  • Video sitemap: Useful when you want to state clearly which pages host videos and what their metadata is.
  • News sitemap: Relevant for publishers who want to appear in Google News. A typical company blog rarely needs one.

You can keep these extensions in separate files or add them to your existing sitemap. For most small and mid-sized sites, though, a standard XML file is enough. If your images sit in normal img tags with meaningful alt text, Google already finds them while crawling the page.

How do you create an XML sitemap?

There are three main ways to generate a sitemap. The right one depends on your platform and on how often your content changes.

  • CMS or plugin: WordPress, Shopify and similar platforms either produce a sitemap on their own or let an SEO plugin do it. When you publish a new post, the file updates too.
  • Dynamic generation in code: On a custom-built site, the application pulls URLs from the database and writes the XML output itself. This is the most flexible route.
  • Online tool: For a small site that rarely changes, you generate the file once and upload it to the root. Our free XML sitemap generator handles exactly this.

The downside of a static file is that you have to update it by hand every time you add a page. So as your publishing pace grows, we suggest switching to automatic generation. If you're still choosing a platform, our comparison of WordPress vs. a custom website covers the SEO side of that decision.

Format is flexible too. According to Google, besides XML it also accepts RSS or Atom feeds and a plain text file with one URL per line. Most content management systems already produce an RSS feed, which can be a quick start for blog posts. However, if you need to carry images, video or language alternates, XML is the only flexible choice.

What should you watch for when generating a sitemap in code?

On a custom site, letting the application generate its own XML sitemap is the cleanest solution. Still, a few technical details decide whether it works well. These are the points our team checks when working with developers:

  • List only live, canonical URLs that return a 200 status code and that you want indexed.
  • Send an XML content type header and generate the file in UTF-8.
  • Escape special characters such as ampersands as XML entities. Otherwise the file fails to parse.
  • Take lastmod from the real content update date in your database, not from the moment the file was generated.
  • Split the output into parts as the page count grows, and serve an index file.
  • On very large sites, cache the output instead of querying the database on every request, and refresh it when content changes.

We care about that last point in particular. Crawlers may request the sitemap often, and running a heavy query each time puts load on the server. In practice, a cached file that you rebuild on publish is both faster and safer.

How do you add a Sitemap line to robots.txt?

Apart from Search Console, the simplest way to announce your sitemap is robots.txt. Google's documentation says you can insert the Sitemap line anywhere in the file. The line doesn't belong to any user-agent group, so its position doesn't matter. A sample file looks like this:

User-agent: *
Allow: /

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

Again, you write a full, absolute URL. If you have several sitemaps, you can add one Sitemap line for each or point only to the index file. The advantage of this method is that search engines other than Google can read the same line.

Watch out for one trap. If you block URLs in robots.txt that you also list in the sitemap, you send contradictory signals. We explain robots.txt syntax and common errors in what robots.txt is and how to create it. If you want to build the file from scratch, our robots.txt generator also lets you add the Sitemap line.

How do you submit an XML sitemap to Google Search Console?

The most traceable way to tell Google about your sitemap is the Sitemaps report in Search Console. It shows whether Google could read the file and how many URLs it found. The steps are short:

  1. Open your property in Search Console. If you haven't verified ownership yet, do that first.
  2. In the left menu, go to Sitemaps under the Indexing section.
  3. Type the file address into the add a new sitemap field, for example sitemap_index.xml.
  4. Click Submit, then check the status column over the next few days.
  5. Review the report again whenever you make a major change to the file.

Google also supports programmatic submission through the Search Console API. That route suits teams that manage many properties. For a single site, though, one submission through the interface is usually enough, because Google rereads the file on later visits. If you're setting up Search Console for the first time, start with our Google Search Console guide.

How do you read the Search Console sitemap report?

Each file you submit appears as a row. The row shows the file type, the submission date, the date Google last read it, the status and the number of discovered pages. Check the status first. A success status means Google could parse the file. If you see a fetch problem or an error, open the file URL in your browser and confirm it actually loads.

Next, look at the second number that matters: discovered pages. If it's far below the number of URLs you expect, the plugin or code may be generating an incomplete file. Remember, though, that a discovered page is not an indexed page. To see index status, click the row and move to the page indexing report filtered by that sitemap.

That filter is very valuable. For example, if many URLs in the product sitemap sit under "Crawled, currently not indexed", the problem isn't discovery. Instead, it's quality or duplication. We cover cases where low value URLs pile up in the index in our article on index bloat and how to fix it.

Does pinging Google with a sitemap still work?

No. For years, a common habit was to notify Google through a special ping URL whenever a sitemap changed. However, Google announced on the Search Central blog that it was retiring the sitemaps ping endpoint. In the same post, it stressed the importance of accurate lastmod values.

So a current setup doesn't need a ping step. If an old plugin or custom script still sends requests to that address, you can safely remove it. Focus on two things instead. First, make sure the sitemap URL sits in robots.txt and in Search Console. Second, make sure your lastmod values reflect real changes.

Then Google rereads your file on its own schedule and prioritizes recrawling pages whose dates it trusts. This approach is simpler and more robust than firing a notification on every publish.

How do you add hreflang to an XML sitemap on a multilingual site?

If you publish in several languages, you can tell Google about language and region alternates in three ways: link elements in the HTML head, HTTP headers, or the sitemap. The sitemap method works across many pages without touching templates, so it is practical on large sites. Here is a sample structure:

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
        xmlns:xhtml="http://www.w3.org/1999/xhtml">
  <url>
    <loc>https://www.example.com/de/leistungen/</loc>
    <xhtml:link rel='alternate' hreflang='de' href='https://www.example.com/de/leistungen/'/>
    <xhtml:link rel='alternate' hreflang='en' href='https://www.example.com/en/services/'/>
    <xhtml:link rel='alternate' hreflang='x-default' href='https://www.example.com/en/services/'/>
  </url>
</urlset>

The core rule in Google's guide to localized versions is this: each language version must list every alternate, including itself. So if the German entry lists an English alternate, the English entry must list the German one too. Google may ignore one-way annotations.

We explain the logic, language and region codes, and x-default in our guide to the hreflang tag. Instead of writing the markup by hand, you can produce correct pairs with our hreflang generator.

What are the most common XML sitemap mistakes?

Most errors we find in audits come from the content of the file, not its format. In other words, the XML is valid, but the URLs are wrong. The most frequent ones are:

  • Noindexed URLs: You ask Google to discover a page you have told it not to index. As a result, the two signals conflict.
  • URLs that return 404 or 410: Deleted products and removed pages stay in the file.
  • Redirected URLs: The file holds the old address while the server sends a 301 to the new one. List the final destination instead.
  • Canonical mismatch: The file holds a parameter or duplicate version, while the page's canonical tag points somewhere else.
  • Mixed protocol or host: Some URLs use http and some https. Some include www and some don't.
  • URLs blocked in robots.txt: You tell the crawler both "crawl this" and "stay out".

The fix is always the same. Put only canonical URLs that return 200 and that you want indexed into the file. We cover canonical signals in our guide to the canonical tag. To check redirected URLs in bulk, try our redirect checker.

Why list only indexable pages instead of every URL?

Some site owners think more URLs mean better results. So they add filter pages, tag archives and internal search results to the file. However, Google recommends that a sitemap contain only the preferred URLs you want to appear in search. For example, if you have separate mobile and desktop URLs, Google suggests pointing to only one version.

That said, there is a practical reason for this. A sitemap is the list where your site tells Google "these are my important pages." If you fill that list with thin, duplicate or unwanted pages, you dilute the signal. You also lose the real problems in the noise of your Search Console reports.

On ecommerce projects we usually suggest a simple split. Main categories, subcategories and product pages go into the file. Sorting, filtering and paginated parameter versions stay out. We go deeper into this in our article on faceted navigation and SEO.

When should you not manage the sitemap yourself?

To be honest, most site owners never need to touch a sitemap by hand. If you run WordPress or a hosted ecommerce platform, the system already produces the file. Your job is to submit its address to Search Console and check the report once a month.

However, we suggest handing the work to a developer or technical SEO support in a few cases. You need dynamic generation on a custom site. You run a multilingual structure with tens of thousands of pages. Or the job involves server configuration, caching and redirect rules. In these cases, one wrong setting can damage discovery for the whole site.

For example, if you leave the old domain's URLs in the file during a migration, Google hits hundreds of redirects and discovery of the new URLs may slow down. Likewise, if staging URLs leak into the live file, you hand Google pages you never wanted indexed.

Also keep in mind that a sitemap alone fixes nothing. If Google doesn't index your pages, the cause usually lies in content quality, internal links or canonical signals. Within our SEO consulting service, a sitemap review is part of the technical audit.

XML sitemap checklist: what should you check before going live?

Before you publish a new file or while you audit an existing one, work through the list below in order. Once you tick every item, you have closed off the main risks.

  1. The file is UTF-8 and valid XML, and it opens in a browser without errors.
  2. Every URL is absolute, and its protocol and host match the canonical version of the site.
  3. Every listed URL returns 200, with no redirects, 404s or noindex tags.
  4. URLs match each page's canonical tag exactly.
  5. Each file stays under 50,000 URLs and 50 MB, with an index file where needed.
  6. lastmod values reflect real content changes.
  7. robots.txt has a Sitemap line and does not block the listed URLs.
  8. You submitted the file in Search Console, and its status shows success.
  9. On a multilingual site, hreflang alternates are reciprocal and complete.

We recommend repeating this list every quarter. Above all, run it after a site migration, a domain change or a major redesign. Those are the moments when old URLs tend to linger in the file.

Frequently Asked Questions

Does an XML sitemap improve rankings directly?
No, a sitemap is not a direct ranking factor. Its job is to help Google discover your URLs and notice pages you updated. Rankings depend on content quality, match with search intent, links and technical health. Still, a page that Google never discovers can never rank, so the sitemap plays an important supporting role in your setup.
Does the file have to be called sitemap.xml?
No, you can choose any file name. Names like sitemap.xml or sitemap_index.xml are common because they are easy to recognize, but other names work too. What matters more is location, because a file at the root can cover the whole site. As long as you reference the correct URL in robots.txt and Search Console, Google finds and reads it.
How often should I update my sitemap?
Update it whenever something important changes on your site. Add new pages when you publish them, remove pages you delete and refresh the lastmod value when the main content of a page changes. That is why we recommend automatic generation through your CMS or code. If you keep a static file, check it on every publishing day.
Why does Search Console show fewer discovered pages than I expected?
The most common reason is an incomplete file. A plugin may leave out some content types, or one of the child sitemaps in your index may return an error. First, open the file in your browser and count the URLs. Then check the status of each child file separately in the Sitemaps report and fix the one that fails.
Does a small business website need a sitemap?
It is not mandatory. According to Google, a site with about 500 pages or fewer and complete internal linking may not need one. Even so, we recommend creating one for most small sites. It costs almost nothing, and it makes tracking index status in Search Console much easier when something goes wrong later.
Should I add images and PDF files to my sitemap?
Only if it helps, and most sites can skip it. You can list PDFs or other files you want indexed as standard loc entries. Images have their own image extension, which helps most when images load through JavaScript. If your images sit in normal tags on the page, Google already finds them while crawling.
  • xml sitemap
  • sitemap index
  • google search console
  • robots.txt
  • technical seo
  • hreflang
  • crawling and indexing
Share:
Talha Aslan

Google Partner digital marketing expert. Hands-on with SEO, Google Ads, web design and e-commerce projects since 2012; every post here comes from that experience.

Next project

Let's talk about your project.

Your brief goes straight to Talha Aslan and team: strategy led by Talha, delivery by an experienced team. The first consultation is free; we listen and come back with a clear roadmap.