On the cusp of its initial public offering, the social-networking giant is set to take advantage of a loophole that could spare the company from having to pay federal taxes for years.

Facebook will be able to claim a huge loss on the shares founder Mark Zuckerberg purchases in his own company — a tax deduction worth as much as $5 billion, according to Sen. Carl Levin (D-Mich.), who yesterday introduced legislation to close the loophole.

Levin, who has fought to end the deduction for 15 years — ever since the days of Enron — is renewing his calls ahead of Facebook’s pending IPO, which is expected to value the company upwards of $100 billion.

In its IPO documents, Facebook said that Zuckerberg will exercise options to buy 120 million shares at just 6 cents apiece. The company can report the cost to investors of issuing those at just $7.2 million.

The actual shares are expected to trade at closer to $40 apiece on the public markets. On that basis, Facebook could claim a $4.8 billion expense deduction on its taxes, which more than wipes out the company’s $1 billion in profits last year.

“Stock options grants are the only kind of compensation where the tax code allows companies to claim a higher expense for tax purposes than is shown on their books,” Levin said.

Also, in its public filings, Facebook said it intends to request a $500 million tax refund from the past two years after it books the “losses” from Zuckerberg’s stock-option compensation, Levin said.

Facebook’s tax tactics are legal, said Silicon Valley accountant Robert Wood, who said the company would be remiss not to take advantage of the tax code.

While Levin looks to close the “loophole,” there are other tax tricks that deserve as much or more attention from lawmakers, Wood said.

Levin introduced an amendment to change the stock-option deductions as part of a broader bill addressing a number of tax loopholes.