To compare two things is to evaluate them in reference to each other, their similarities and their differences. Both prepositions to and with may be used with this verb (e.g., compared to and compared with).
In most situations they can be interchangeable and your meaning will be clear. A century ago, with was the favorite. Now it has fallen out of favor and compared to is found more often.
If you or your audience are focused on nuances, there is a traditional distinction between the two prepositions. But again, most of the time this difference is disregarded and to is the favored preposition for all comparisons.
Compared with is usually referring to two objects of similar classification (e.g., dogs to dogs and cats to cats). Within this similar order, the user is speaking of the differences between the two objects of comparison.
Compared to is referring to two items in different classifications (e.g., dogs to cats or cats to cars). In these differing classifications, the user is pointing out similarities between the two seemingly unrelated objects.
Again, most of the time the difference in meaning between to and with goes unnoticed by readers. However, there is always one or two that will appreciate the distinction.
Oil and natural gas producer Hess Corp reported a loss compared with a profit a year earlier, when it reported after-tax gains of $1.34 billion related to asset sales. [Reuters Africa]
Fewer than 1% of public-sector employees lost their jobs in 2013, compared with 3.3% in the private sector. [Business in Vancouver]
It showed that a drought that affected the American West from 2000 to 2004 compared to conditions seen during the medieval megadroughts. [The Washington Post]
Despite the heavy decline in its share price, this stock is still more expensive (when compared to its current earnings) than most other companies in its industry. [The Street]