They can't compress the photos, because photos are almost certainly already compressed, either with JPEG or PNG compression, and it's not possible to compress already-compressed data. (That's oversimplifying it a bit, but unless you want to get deep into information theory, just accept that as a given.)
There's really no shortcut. A site that holds massive amounts of data has massive amounts of computers to hold it on.
Let's say an image weighs in at 1 MB. There are plenty that are bigger, and plenty that are smaller, but just for simplicity's sake let's say the average image is 1 MB. It's not hard to find affordable 2 TB drives these days, which means that each drive could theoretically hold around 2 million images. (Obviously there will be some space lost to overhead, but you get the idea.)
A server can have a RAID configuration set up with multiple hard drives. Some of the data is lost to redundancy, but even so you can have several TB worth of drives per computer. And a server farm can hold dozens, hundreds, or even thousands of servers. That's how sites like Pinterest and Facebook manage so much content.
They tend to have massive server farms, with computers in front of them that route requests from Web browsers, looking up the content in the appropriate place in the server farm and serving it back to the user. It's a really big topic to try to cover here, but that's the basic idea.
http://www.howstuffworks.com/pinterest.htm havent u seen this? – BlueBerry - Vignesh4303 – 2013-10-22T04:39:46.713
4Yes, they just store them. Storage is cheap relative to cpu and memory. – Paul – 2013-10-22T04:39:49.083
4One thing that a site like Pinterest can obviously do is deduplication: store each image only once, no matter on how many people's pages it appears. – Michael Borgwardt – 2013-10-22T05:46:17.083
My guess is, more than 1 hard drive! :) – Dave – 2013-10-22T07:52:45.457