San Francisco’s Mayor London Breed is expected to sign the largest budget in the city’s history in a few weeks at more than $12 billion.

It’s more than recent budgets for small states such as Rhode Island, Maine and Delaware.

And it prompts the question: Why does a city with a multibillion-dollar budget have so many gripping problems on its streets?

The city’s crises are no secret. Its waiting lists for shelter beds for the homeless run more than 1,000 nearly every night. Car break-ins are rampant. Sidewalks are littered with human waste, needles and trash.

But the magnitude of the budget eclipses the complex reality of how much money the mayor and Board of Supervisors can actually freely spend each year.

“People are always complaining and always saying, ‘Well, we have a $12 billion budget,’” said Supervisor Sandra Lee Fewer, chair of the Budget and Finance Committee. “But really … the mayor doesn’t have control over $12 billion. And neither does the Board of Supervisors.”

Due to a patchwork of voter mandates, and state and federal rules, the majority — about 73% — of San Francisco’s budget was already accounted for before Breed and the supervisors could get their hands on it.

Every year, just over half of the total budget gets shunted to enterprise departments, such as the airport, the San Francisco Public Utilities Commission and Municipal Transportation Agency, which generate some of their own revenue. The city also has about 20 voter-mandated set-asides that lock in funding for tree maintenance, libraries, parks and other needs.

Set-asides guarantee that some city needs get funded on an annual basis, no matter the politics or policies of the moment. But they also make it hard for the city to quickly move money around to address emergencies, like the homelessness crisis, without going back to the voters.

Then comes the city’s biggest expense: salaries for its 31,800 full-time positions. The average compensation for city employees is now $175,004 a year, including salary and benefits.

“People look at the sticker price and think that it’s a big budget, but they are not seeing the amount of bodies it takes” to run the city, said Tracy Gordon, a senior fellow with the Urban-Brookings Tax Policy Center. “But because San Francisco is an expensive place to live, you have to pay people more money so that the city can compete with other employers.”

After that, City Hall is left with about $3.5 billion to decide how to spend.

The mayor and board struck a late-night deal Wednesday on how they want to spend that money after spending weeks hammering out the details. To little surprise, much of the increased spending went toward bolstering the city’s response to housing, homelessness and mental health care services. But $3.5 billion is still a lot of money for the city to decide how to spend, Gordon said.

San Francisco’s “resources are broad, its reach is ambitious and it has a lot of needs,” Gordon said. “You want to distribute resources and make people better off, but programs can be inefficient and once you provide a benefit, more people want it.”

In some places, the city has admitted to glaring inefficiencies in its spending. In the Department of Public Health, for example, Breed and Director Dr. Grant Colfax admit the city’s behavioral health system isn’t working as well as it should and needs more funding. In response, they hired a new director for $319,000 a year to look at the system and recommend changes. Breed also increased funding for more mental health and substance abuse beds in the upcoming budget.

But two supervisors didn’t feel that was enough to fix the city’s broken mental health care system. Their answer? Another ballot measure, another tax, another program.

Here’s a breakdown of how the city plans to spend taxpayer dollars over the next two fiscal years:

Trisha Thadani and Dominic Fracassa are San Francisco Chronicle staff writers. Email: tthadani@sfchronicle.com, dfracassa@sfchronicle.com Twitter: @TrishaThadani, @dominicfracassa