Canonical URLs prevents website to get duplicate content penalty by search engines. Canonical URL can be from the same website or from another website. Canonical URL is specified within <head> tags in <link> tag in the format below.
<link rel="canonical" href="URL" /> URL is the link address or URL of the webpage from where the content has been duplicated.
The search engine passes the SEO credit to the original page i-e specified in the ‘href’ attribute in the above code snippet. It is up to search engines to index or rank pages having canonical link specified. In general, search engines visit the page, checks the canonical link if present, and rank that original page instead of it. But this is not a confirmation nor researches has shown this exact result. Many pages still rank even having canonical links specifications. But to avoid or prevent duplicate content penalties, specifying the canonical link is the most useful tool.