Cars are now more complex than airplanes -– at least when it comes to lines of software code -- and while that makes driving more convenient, it may also be causing bugs and breakdowns along the road, experts say.

At the same time, car manufacturers are outsourcing hundreds of thousands of bits of technology that go into a modern car, making it tougher to ensure quality control. This week, the General Motors CEO Mary Barra faced tough questions on Capitol Hill over the failure of an inexpensive ignition switch that may have led to the deaths of 13 people.

Top 10 Movie Star Cars: Photos

The switch turned the vehicle into accessory mode, which shut off power to airbags in the Cobalt, Saturn Ion and other vehicles. On Wednesday, David Friedman, acting administrator of the National Highway Transportation Safety Agency told a Senate panel that the failure “doesn’t make sense to me” and said that scrambled computer logic could be to blame.

It’s just the latest in a string of bad news for carmakers:

  • Last week, Nissan issued a recall for about 1 million Altima, Leaf, Pathfinder, Sentra and Infiniti models with a software glitch that could prevent certain airbags from deploying during collisions.

  • In February, Toyota recalled nearly 2 million brand-new Priuses for a software bug that could cause the car to stall.

  • GM in March recalled its new all-electric Cadillac ELR for a software glitch in its cruise control. It also just stopped selling the Chevrolet Cruze, but won’t say why.

Has something gone haywire under the hood?

“The complexity of software in a vehicle is daunting,” said James Freudenberg, professor of electrical engineering and computer science at the University of Michigan and a leading expert in vehicle software.

“You can’t reboot it. You can’t open a window on your laptop and modify it in any way. It has to work in many modes of operation, not just driving down the road, but also when it’s cloudy, rainy, freezing or hot. It gets complicated very quickly.”

A car transporter picks up recalled vehicles from a dealership.Kevork Djansezian/Getty Images

Freudenberg said that most vehicle software monitors sensors that provide diagnostic information on mechanical parts of the car and its engine. The average Ford in 2010 had 10 million lines of code, more than the Boeing 787 Dreamliner.

As the number of embedded systems (software that works inside other devices) increase, so does the possibility for unanticipated failures. That’s because engineers can’t test for every combination, Freudenberg said.

Top 10 Movie Star Cars: Photos

“Software has tens of thousands of variables that interact in all kinds of ways,” Freudenberg said. “There are bugs that only occur in certain circumstances, you can’t predict.”

While cars are safer than they were decades auto, automotive engineers have loaded up vehicles with lots of things that aren’t related to driving.

“A lot of people like convenience,” said Arthur Wheaton, faculty member at Cornell University’s lnstitute for Labor Relations. “It’s getting exponentially worse where we are putting tele-informatics into the car so that it can work with an iPhone or something else. Each one of these has forced the level of complexity through the roof.”

Flying Concept Car Could Hover Over Congestion

Wheaton noted that Detroit automakers are under pressure to keep costs down, as as a result, are outsourcing more of their software coding to programmers overseas. That makes it more difficult to integrate it into the rest of the vehicle and check for bugs.

“It’s difficult to dedicate the amount of resources to make sure it’s foolproof,” Wheaton said. “If you were trying to make it engineering perfect you would have to spend an outrageous amount of money.”

In the end, though, auto manufacturers end having to pay.