Summary: It is a way of informing Search engines about pages available on a website, like URL, when last it was updated, how frequently will it be updated, and the priority/importance of the webpage compared to other pages on the site.
In sitemap.xml, as per the sitemaps.org standard, you can specify 4 things about the page.
Generally, it should be located in the root directory of the website, like
However, it can be placed at any level of your website, for example
However, in that case, the sitemap.xml file include only URLs that are at the same level as the sitemap.xml file or lower than it, not at a higher level than it.
For example, if the location of the sitemap.xml file is
It can include only URLs that are the same or at a lower level than it is
but not URLs at a higher level than it
There any many other complex rules that can be found on the official website: https://www.sitemaps.org/protocol.html#location
As per the standard, a sitemap.xml file cannot contain more then 50,000 URLs and the size of the file must not exceed 50MB size. What to do when we have a large number of URLs that exceed this limit?
The answer is a sitemap.xml index file. A sitemap.xml file that points to other sitemap files.
The pointed file can also be another index file.
There are many deep and technical things are there about sitemap.xml file, which can be found on its official website https://www.sitemaps.org/protocol.html
This is how you provide information about the pages of your website to the search engines. How to use this information is up to the search engine. Google ignores "changefreq" and "priority" - https://developers.google.com/search/docs/crawling-indexing/sitemaps/build-sitemap#additional-notes-about-xml-sitemaps