DECATUR, Ill.— Norfolk Southern Corp. executives, employees and customers holed up for five days recently to work on a complex puzzle. How could they unclog a sprawling freight yard in central Illinois without triggering chaos?

They asked a multitude of small questions akin to word problems in a math class. Their answers point toward some of the most sweeping changes to the nation’s railroad system in decades.

There are 19 railcars bound for Kansas City that reach Decatur around 7:10 a.m. most days, about two hours before their connecting train. That isn’t enough time to unhook the cars, which are loaded with freight like coiled steel and corn syrup, move them along a grid of tracks, then attach them to the outbound train. So they sit in Decatur for an average of 26 hours—well over Norfolk Southern’s goal of 20.

Pushing back the Kansas City departure to 2:30 a.m. the following day would fix that problem but generate another: 21 cars from Conway, Pa., would miss the train to Kansas City. One fix would be to have the Conway train arrive later.

“It’s a cascade,” says Todd Reynolds, general manager of Norfolk Southern’s western region.