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 L. Yellen during her visit to Beijing this week 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.

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 percent of the country’s annual economic output. That compares with an average of 256 percent in developed economies around the world and 257 percent in the United States.

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 United States 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 percent 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.

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 have instead done the heavy borrowing to buy the land that such developers could no longer 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 percent of China’s annual economic output. Their affiliated financing units owe debt equal to an additional 40 to 50 percent 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.

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.

Almost two-thirds of the world’s developing economies depend on commodity exports. The World Bank forecast in April that commodity prices will be 21 percent lower this year than last year.

In 2010, only 5 percent of China’s overseas lending portfolio supported borrowers in financial distress. Today, that figure stands at 60 percent, said Bradley Parks, the executive director of AidData at William & Mary, a university in Williamsburg, Va.

China is by far the largest sovereign lender to developing countries, although Western hedge funds have also bought many bonds from these countries. The bonds tend to be at fixed interest rates. But China’s banks have tended to lend dollars at adjustable interest rates that are linked to rates in the West. As the Federal Reserve has pushed rates up steeply since March 2022, developing countries have faced soaring debt payments to China.

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. “The biggest losers will end up being ordinary people in the developing world who are denied basic public services because their governments are saddled with unsustainable debts,” Mr. Parks said.

China’s domestic debt overhang defies quick fixes. The country needs to gradually move away from debt-fueled government construction projects and heavy national security spending, toward an economy based more on consumer spending and services.

Powerful constituencies in Beijing and Chinese provincial capitals protect the current economic priorities. Ms. Yellen will be trying to learn more about China’s economic plans, but can do little to influence them.

Last winter, 21 Chinese banks agreed to let a local government financing unit in southwestern China extend to 20 years the repayment of loans that were close to coming due, and said that only interest payments, not principal, needed to be repaid for the first 10 years. But that arrangement meant heavy losses for the banks — and almost every province in China has similarly troubled local financing units.

Yet solving the developing country debt problem will be hard. “Yellen’s ability to exhort China to accept debt write downs is limited,” said Mark Sobel, a former longtime United States Treasury official. “The U.S. and Yellen have little leverage,” he added.