Your hellish commute didn’t happen overnight — it took 50 years for the subway to get this bad.

The MTA spent decades without a capital plan to systematically replace aging infrastructure — and when it did get one in 1981, the agency spent years doing triage to prop up a badly broken system with insufficient funds, experts say.

Now they are playing catch-up, there is no light at the end of the tunnel.

“As the usage of the system has increased, the MTA capital investment hasn’t kept pace with the needs,” said Richard Ravitch, who was MTA boss in the 1980s and helped bring the system back from the brink of death the first time.

The situation isn’t nearly as dire now as it was in 1981, but the subways now have more than twice the ridership, and commuters can now never quite be sure if they’re going to make it to work on time or home for dinner.

“We are still playing catch-up to fix the sins of 1970s neglect and disinvestment,” said spokeswoman Beth DeFalco.

“Ridership is up 64 percent since the first Capital Plan was enacted but we do not have 64 percent more infrastructure. We are constantly working to provide regular service for our customers amidst growing ridership and capacity constraints.”

The agency’s capital plan has always been lacking. When the MTA passed its first capital budget in 1981, the subway system was a chaotic hazard. Trains regularly caught fire, derailed and collided. That first capital plan was basically triage meant to keep the system from descending further into turmoil.

“In 1981, the system was covered in graffiti, grime and crime. It was worth $27 billion — less than the amount we will invest in capital improvements in the next five years,” said DeFalco.

That first 1982-1986 plan was just $7.2 billion, or $19.4 billion in today’s dollars. That’s less than 60 percent of the money the agency is spending now on replacements and new projects.

But the agency still didn’t have a plan for regularly replacing tracks, signals and cars.

In the 1990s, the capital budgets were cut, and the MTA was expected to get more money from borrowing instead of being mostly funded by the feds, state and city.

So the system got older and more parts aged beyond their useful life.

Meanwhile, the capital plan amounts stagnated and less work got done. The 1992-1996 plan was only $10.2 billion, or $20.4 billion in today’s dollars, and much of the system infrastructure was left neglected.

For its current 2015-2019 capital plan, the MTA initially said it would need $20 billion for maintenance and repairs. But after funding negotiations were done, it ended up with only $12.3 billion for “repairs and normal replacement,” which is nearly $7 billion, or 38 percent, less than what it needed, according to an analysis done by the Citizens Budget Commission.

And that’s not enough to fix the system when 11 percent of the cars are more than 40 years old and many of the signals date back to the 1930s.

“The entire signal system needs to be redone,” said former board member Allen Cappelli.

It would take $35 billion in maintenance funding to get the city’s subways back to a state of good repair, MTA experts say. And that’s nearly double what is in the agency’s current capital plan for repairs and replacements.

“This is a dinosaur,” Michael Horodniceanu, the MTA’s newly retired head of construction, said of the subway system. “You have to feed the dinosaur.”

But the MTA can’t keep blaming the past as it scrambles to fix the system, say critics. The state needs to step up and find ways to fix the problem that don’t take another 40 years, they said.

“Gov. [Andrew] Cuomo didn’t invent the system of under-investing of public transit. But he has been governor for more than six years and he has been taking money away from the MTA instead of finding money for mass transit,” said John Raskin, executive director of the Riders Alliance. “The governor should put forth a plan on how the MTA will upgrade the equipment so we have modern signals and new subway cars and reform operations so construction costs are more manageable.”