Canonical URL: Canonicalization is a process for converting data that has more than one possible representation into a “standard” canonical representation. A canonical URL, therefore, is the standard URL for accessing a specific page within your website. For instance, the canonical version of your domain might be http://www.domain.com instead of http://domain.com.
Canonical URLs are actually two copies of your same website. One with www and the other without www.Google treats these websites as two different websites. If you don’t tell Google which is your preferred site (you can set your preferred site in Google Webmaster Tool) then Google will index and rank both of your sites individually and it may happen that your own site acts as enemy to your site. This is because if these sites were not ranked individually, then your overall search engine ranking would have been much higher (combined of www and non www).
So, use Google Webmaster tool and set your preferred site (www or non www) and you might use a 301 redirect if yours is non – wordpress blog. If you use wordpress blog then you can simply set this in general settings (just mention the URL name).
We need use 301 redirect because, we really can’t control how other links to our site. (They may link us www or non www version). Redirect safely lands them to preferred domain