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 iPhone maker released its second-quarter earnings report on Tuesday, announcing profit declines for the first time in a decade and an "eye-popping" $60 billion stock buyback program, said Michael J. de la Merced at The New York Times.

The stock buybacks will certainly make investors happy. They've been clamoring for Apple to spread its wealth — the company reportedly has a cash hoard of $145 billion — among shareholders for months.

But instead of writing a check from its supersized bank accounts, Apple executives said the firm plans to sell an unspecified amount of debt to pay for its expanded buyback program.

"Why is Apple borrowing money to pay investors when it has more cash than ever?" asked Tim Fernholz in Quartz. "The answer is 'taxes.'"

Peter Lauria at BuzzFeed breaks it down:

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.

Apple isn't alone, of course. Last month, The Wall Street Journal looked at 60 U.S. companies and "found that, together, they parked a total of $166 billion offshore last year" and "shielded more than 40 percent of their annual profits from U.S. taxes."

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."