Apple may be sitting on mountains of cash, but its credit rating got dinged this week after executives announced that the company would borrow money to finance its multi-billion dollar shareholder payout plan.

The real reason Apple is borrowing money is because more than two-thirds of its $145 billion cash pile resides overseas, and bringing it back to the U.S., known as "repatriating," would subject the company to a huge tax hit. According to U.S. tax law, the income companies earn from operations overseas aren't subject to taxes provided they remain overseas. [BuzzFeed]

In other words: Borrowing money to pay its shareholders actually costs Apple less than paying taxes on its massive cash piles.

All that untaxed cash could be a big boost for U.S. coffers. A congressional taxation committee estimated that changing the law to fully tax overseas earnings could generate an extra $42 billion for the Treasury each year.

Lawmakers have also toyed with relaxing taxes on repatriated cash, hoping it might boost the economy. In 2004, Congress enacted a temporary tax holiday, "prompting companies to repatriate $312 billion in foreign earnings," according to the Journal. But studies found the influx of cash created "few jobs" and "most of the money was used to repurchase shares and pay dividends."