What a canonical tag is
The canonical tag is <link rel="canonical" href="..."> in the head of a page. It names the URL you want search engines to index and rank when the same content is reachable at several addresses, so signals such as links are consolidated on one URL instead of split across duplicates.
Duplicates are common: tracking parameters (?utm_source=), sort and filter parameters, http and https or www and non-www versions, printer views and products listed in several categories.
A hint, not a directive
Google treats the canonical tag as a strong hint. It may choose a different canonical when other signals disagree, for example when internal links, the XML sitemap and redirects all point at another URL, or when the pages are not actually similar.
Make every signal agree: link internally to the canonical URL, list only canonical URLs in the sitemap and use 301 redirects where duplicate URLs need not exist at all.
Best practices and common mistakes
Use absolute URLs, add a self-referencing canonical on every indexable page, and keep a single canonical tag per page. Avoid canonicalising to a URL that redirects, returns 404 or is noindex, canonicalising every paginated page to page 1, and pointing all language versions at one page when you use hreflang.
Example
A canonical on a parameter URL:
<!-- On https://example.com/shoes?sort=price&utm_source=newsletter -->
<link rel="canonical" href="https://example.com/shoes">