Facebook has confirmed it is buying up a boatload of patents from IBM — 750 in all — that will help the company shore up against potential legal attacks from Yahoo and other companies claiming the huge social network infringes on their intellectual property.

But for the past couple of years, Facebook has already been taking steps to build up its patent portfolio through the acquisition of patents from a host of other players, from large IT companies, to a patent troll and a defunct social network. And a few surprises. A closer look at this gives some clues as to why it’s so important for Facebook to acquire patents rather than try to build up the portfolio itself.

Of the 60 patents that Facebook now owns that are listed with the U.S. Patent and Trademark Office — among a list of 160 in all, counting both applications for and assigned patents — there are 15 from Facebook itself; and nine patents from HP, 11 originally from Philips Electronics (but sold to IPG and then sold by IPG to Facebook), three from UK telecoms operator BT, nine from patent holder Walker Digital, one from Divan Industries, one from Applied Industries and 11 from Friendster — the pioneering social network that died a Facebook death and eventually got sold to Malaysian company MOL, which turned it into a gaming network. These were reportedly bought for $40 million in 2010.

The patents cover a wide range of areas. Some are very much in the wheelhouse of what we know as Facebook today — managing social relationships, newsfeeds and contacts, for example. Some are about technical processes that happen behind the scenes.

And some seem to cover functions that Facebook doesn’t really offer today. One relates to playlists for music or other media (“Method and apparatus for priority-based jukebox queuing”, patent number 6421651). Others seem to have a distinct e-commerce bent (“Systems and methods wherein a buyer purchases products in a plurality of product categories”, 7188080; “Method, computer product and apparatus for facilitating the provision of opinions to a shopper from a panel of peers”, 7526440).

(At first, I wondered if this pointed to areas where Facebook wants to potentially offer services — a marketplace seems to make perfect sense, for example. One, possibly ligitation-minded, patent lawyer gives me another opinion: “One thing we teach new companies is not to buy patents in their domain but in competitors’ domains where they can do most harm in lawsuit,” he says. “My expected competitor [eg] is Google, so I buy in areas like search, computing centers, and e-commerce to hurt them.”)

Indeed, the U.S. Patent Office also lists another 100 patent applications that have yet to be either approved or formally rejected. Many of these have been initiated by Facebook itself.

Yet there are also some that Facebook has picked up while they are still pending. These include four more patents originally owned by Friendster and one more e-commerce patent from Walker. And surprisingly, one from the energy and services giant Halliburton, related to data centers (“Cooling computing devices in a data center with ambient air cooled using heat from the computing devices”).

Digging into some of the back-and-forth around pending applications also gives a glimpse as to why it’s so important for Facebook to acquire patents rather than try to build up the portfolio itself.

It can take years to get a patent approved, and in the case of social media and gaming the process can take even longer, typically up to six to eight years or more from the time the application gets filed. And it’s hard to get patents approved in this area. (One, for example, filed by Facebook for “Facilitating Interaction Among Users of a Social Network,” was originally filed in July 2010, and just last week had a “non-final rejection” of all of its claims. Facebook can still modify and resubmit.)

Meanwhile, the potentials for lawsuits appear to be building up.

“Facebook is really the new kid on the block and they need to gird and prepare themselves with IP because the bigger kids have it,” a patent lawyer explained to me. “They have definitely been very proactive, though. Someone at that company understands that the key to a good defense is a good offense.”

So is 60 the definitive number of patents that Facebook owns today? Not necessarily: this is the number listed by the U.S. Patent Office but the patent lawyer tells us that there could be more that it has simply not registered. “There’s no requirement to record every patent with the USPTO,” he said. “It’s only something you do if and when you want to enforce it.” Although he does point out that it’s generally good practice not to stockpile patents.