Forum Moderators: open
If Google identifies the two URLs as having identical content, then the two URLs will be merged in Google's database and whichever one is kept will be credited with both sets of backlinks.
Often the reason for the difference is that Googlebot visits the URLs at different times during the cycle, so the content may have changed.
From RFC 1034 [ietf.org], "Domain Names - Concepts And Facilities":
A domain is a subdomain of another domain if it is contained within that domain.
So www.example.com, example.com, www2.example.com, widget.example.com, and www.widget.example.com can all be different. Each domain just points to an IP (can be the same or not), and the server on each will in all normal situations check the 'host' header to decide which content to deliver. Although it is often the case the www.domain and domain are the same (or that one redirects to the other), it would be wrong for Google to make that assumption.
In Google, the search for "widgets site:widgets.com" gives all of the results that "widgets site:www.widgets.com" gives, but with pages on the widgets.com domain and other subdomains in addition.
edit_g:
> So if they are different domains- shouldn't sites get penalised for duplicate content somehow?
Hopefully not. If Google finds that the content is identical then it will normally merge the results. This might seem like a penalty (only getting one listing not two) but IMO you are much better off with just one listing that has the combined backlinks (and PageRank).
> I must say I haven't noticed this- they must have some sort of check going- because it is very common for the www.mydomain.com and mydomain.com to have identical content.
They do have a check, but it applies to www.mydomain.com and www.myotherdomain.com as well. It just happens that www.mydomain.com and mydomain.com are often duplicates.