What problem does a canonical URL solve?
The same page is often reachable at more than one address: a link with a tracking parameter, a www and a non-www host, and so on. RFC 6596 from the IETF defines the canonical link relation as the one that names the preferred address among resources with duplicative content [2]. Search engines can then concentrate on that preferred address [2].
How do you declare one?
Google lists several methods and ranks them by strength. A redirect is a strong signal that its target should become canonical. A rel="canonical" link annotation is also a strong signal and can sit in the page's head or, for non-HTML files such as PDFs, in an HTTP header. Listing a URL in a sitemap is a weak signal [1]. Combining methods makes it more likely that your preferred URL is the one that appears in results [1].
Will Google always use the one I pick?
Not necessarily. Google treats these methods as preferences, says none of them is required, and when no preference is given it picks the version it considers best to show users [1].
A concrete case from Google's documentation: a green dress page can be reached at /dresses/green/green-dress.html and also at an address carrying an ad parameter such as ?gclid=ABCD. The owner marks the first as canonical [1]. RFC 6596 uses a similar example, where URLs with an added session ID or category parameter point to page.php?item=purse as the preferred version [2].