Where towns get built throughout history may seem pretty random to the modern eye, but there’s actually a pretty simple calculus that can explain why cities develop where they do, according to a new video, spotted by Gizmodo, from the explainer YouTube channel Wendover Productions.

If each town is only 10 miles from another, people within that 10-mile radius only have to travel five miles to get to the nearest town to buy or sell goods—which was useful before cars. Rural areas that built towns before the auto age often have towns only about 10 to 15 miles apart for this exact reason.

People don’t want to walk very far to get something they buy every day, like coffee, but will venture farther to make a rarer purchase, such as new tires or a new laptop. Shops that people visit all the time tend to be more common because they don’t need as many individual customers to stay afloat. Meanwhile, specialized businesses that consumers shop at infrequently generally need to be located in areas with higher populations.

However, geographic considerations can change that model. It’s hard to build cities on mountains and move goods across ranges, but mountains can also protect against invading forces, and they can have resources like coal and gold. Cities are built on ports so merchants can move goods in and out efficiently. Rivers are necessary to provide a water source for citizens as well as a transport route to the ocean. If there are natural resources, people have historically gravitated toward them, setting up shop right where they can grow crops or build factories.

And that’s before you even consider the history of how Europe and Asia developed early empires, which one theory hypothesizes could be due to climate similarities across continents from east to west, and differences from north to south.

Watch the full video for a much more in-depth explanation:

[h/t Gizmodo]