Facebook(FB  ) is due to begin a court battle with the IRS in a case that could cost the social media giant $9 billion dollars and rewrite the way the government's crackdown on companies that shift profits to low tax countries.

In 2008, as Facebook started gathering 100 million users and emerging as the next big tech company, it acquired an important hire. Sheryl Sandberg was leaving Google (GOOGL  ) to become Facebook's chief operating officer.

Sandberg advised the growing company should explore ways to lower its tax burden. "My experience is that by not having a European center and running everything through the U.S., it is very costly in terms of taxes," she wrote in an April 2008 email.

Later that year, Facebook named Dublin as its international headquarters just like Google did during Sandburg's tenure. Facebook's Irish headquarters paid royalties to its U.S. parent for the use of the social media giant's intellectual property. The lower the value, the fewer royalties the Irish unit would have to pay to the U.S. This would leave more profits in the Irish unit where it would face lower taxes, and less in the U.S. where it would have been taxed at 35%.

If Facebook wins it would make it harder to pursue these types of cases in the future.

That could be a big deal for the government considering the number of tech companies with Irish subsidiaries. For example, in 2018, Apple (AAPL  ) had $252 billion in cash held overseas and paid $38 billion in one-time taxes.

If the IRS is unable to win against Facebook, other companies could challenge the agency's determination that they owe taxes on the estimated value of assets held outside the United States.

If Facebook loses, it could face a substantial tax bill that exceeds even its $5 billion settlement with the FTC last year over privacy violations.