Peter Thiel, Facebook's first big investor, has sold off most of his stake, turning his initial $500,000 investment into more than $1 billion in cash.

Thiel became a Facebook investor in 2004, when Mark Zuckerberg first set out to turn his dorm room project into a lasting business. Thiel and his associated investment funds held more than 44 million shares of Facebook when the company went public. He sold off 16.8 million shares in the IPO, netting $640 million.

Facebook's lockup rules required some early shareholders, including Thiel, to hold on to their remaining stock for a certain period. That period ended on Thursday, setting more than 270 million shares free.

Thiel took advantage. He and his funds sold off 20 million shares, worth a total of $395.8 million, according to a regulatory filing. The stock sales, made at per-share prices that ranged from $19.27 to $20.69, took Thiel's total Facebook cash-out to just over $1 billion.

The stock sales represent a near-exit for Thiel, who has now liquidated almost all of his Facebook holdings. He and his funds are still sitting on around 5.6 million shares, worth $112 million at Monday's closing price.

He didn't sell because of Facebook's (FB) slumping stock price, though: The regulatory form revealed that Thiel locked the sale plans in place on May 18, the day of Facebook's IPO. His plan was to cash out his holdings when the lockup expired, no matter what price Facebook's shares were trading at.

Related story: Who sold off their Facebook shares

Thiel will score a tidy sum for himself, but he won't take home the full $395 million. Some of it will go to investors in the funds through which he bought the shares.

Facebook is Thiel's second big Silicon Valley windfall. He made his first, smaller fortune from PayPal, where he served as CEO until eBay acquired the firm in 2002. He has gone on to become an active investor in and adviser to scores of other startups.

Other funds also distributed Facebook shares last week to their investors. In a sign of just how interconnected Silicon Valley is, some of those shares went to Netflix (NFLX) CEO Reed Hastings, a Facebook board member who recently spent $1 million buying Facebook shares on the open market.

Hastings is also an investor in Accel Partners. When Accel distributed shares, Hastings picked up almost 22,000 more shares -- valued at around $435,000 -- to add to his stash.