China, which has lent nearly $1 trillion to some 150 developing countries, has been reluctant to cancel large debts owed by countries struggling to make ends meet. That is at least in part because China is facing a debt bomb at home: trillions of dollars owed by local governments, their mostly off-the-books financial affiliates and real estate developers.

One of the main issues for Treasury Secretary Janet Yellen during her visit to Beijing this weekend is whether she can persuade China to cooperate more to address an evolving debt crisis facing lower-income countries. But China’s state-controlled banking system is wary of accepting losses on foreign loans when it faces far greater losses on loans within China.

How much debt does China have?

It’s hard to know exactly because official data is scant. Researchers at JPMorgan Chase calculated last month that overall debt within China — including households, companies and the government — had reached 282% of the country’s annual economic output. That compares with an average of 256% in developed economies around the world and 257% in the U.S.

What distinguishes China from most other countries is how fast that debt has accumulated relative to the size of its economy. By comparison, in the U.S. or even deeply indebted Japan, debt has risen less precipitously. The steep increase in China’s debt, more than doubling compared with the size of its economy since the global financial crisis 15 years ago, makes managing it harder.

China’s lending to developing countries is small relative to its domestic debt, representing less than 6% of China’s annual economic output. But these loans are particularly sensitive politically. Despite heavy censorship, periodic complaints emerge on Chinese social media that banks should have lent the money to poor households and regions at home, not abroad. Accepting heavy losses on these loans would be very unpopular within China.

How did China get into such a deep debt hole?

It started with real estate, which suffers from overbuilding, falling prices and beleaguered potential buyers. In the past two years, several dozen real estate developers that borrowed money from overseas investors have defaulted on those debts, including two more in recent days. Developers have struggled to continue paying far larger debts to banks inside China.

Compounding the problem has been borrowing by local governments. Over the past decade, many cities and provinces set up special financing units that were lightly regulated and borrowed heavily. Officials used the money to cover daily expenses, including the interest on other loans, as well as the construction of roads, bridges, public parks and other infrastructure.

The real estate and government debt problems overlap. For many years, the main source of revenue for localities came from the sale to developers of long-term leases for state land. As many private-sector developers have run out of money to bid for land, this revenue has fallen. The local financing affiliates instead have done the heavy borrowing to buy the land that such developers no longer could afford, at steep prices. As the real estate market continues to weaken, many of these financing affiliates are in trouble.

That debt has piled up. Fitch Ratings, the credit rating agency, estimates that local governments have debts equal to about 30% of China’s annual economic output. Their affiliated financing units owe debt equal to an additional 40% to 50% of national output — although there may be some double-counting as local governments borrow and then shift the debt to their financing units, Fitch said.

Why does this matter?

For any government or business, borrowing can make good economic sense if the money is used productively and efficiently. But borrowers who binge on debt that doesn’t generate sufficient returns can get into trouble and struggle to repay their lenders.

That’s what has happened in China. As its economy slows, a growing number of local governments and their financing units are unable to keep paying interest on their debts. The ripple effect means many localities lack money to pay for public services, health care or pensions.

Debt troubles have also made it hard for banks in China to accept losses on their loans to lower-income countries.

Yet many of these countries, like Sri Lanka, Pakistan and Suriname, now face considerable economic difficulties.

If little is done to reduce their debt, many of the world’s poorest governments will continue to spend heavily on debt repayment, money that could otherwise be used for schools, clinics and other services.