You learn to put up with a lot when you live in Mexico State. The electricity is always going out, and there’s never enough running water. Commutes of two to three hours are common. Kidnapping is a booming business, and security is weak. But you decide it’s worth it, because Mexico State is close to Mexico City. And Mexico City is the country’s economic and cultural beating heart.

People in Westchester county feel the same way about New York City. That’s where their jobs are. That’s where they go out. Westchester is expensive, sure, but it’s worth it to have access to New York without, you know, actually having to live in New York. And have you checked out those public schools lately?

Sure, the mansions and parks and well-maintained roads of Westchester are a far cry from the self-built houses and flooded sewers of Mexico State. But they are two sides of the same 21st-century coin: the megacity. New research suggests that only one of them is an environmental disaster—and it’s not the one you think.

Megacities are metropolitan areas with more than 10 million people. The world had 27 of them in 2010; by 2020 it’ll be closer to 40. Megacities encompass the architecturally coherent, energy efficient, culturally vibrant urban cores of New York or London or Tokyo—what we like to think of cities—but they include places like Westchester and Mexico State: the sprawl, the slums, the suburbs, the factories, the ports, and everything else that keeps that central city’s engine running.

In 2010, 6.7 percent of the human beings on Earth lived in a megacity. That number is only going to go up. Those people are going to need resources, and they’re going to generate waste. Christopher Kennedy, an engineer who studies “the metabolism of cities” at the University of Toronto, decided to calculate just how much. It wasn’t easy. Megacities tend to incorporate dozens of municipal governments, each with its own way of providing resources to its residents. Twenty-eight researchers in 19 countries helped Kennedy collect the data about what each megacity consumed and produced in a year, and they’ve published their results today in Proceedings of the National Academy of Sciences. Here’s what they came up with:

WIRED

Cities tend to produce more than their per-capita fair share of economic and social activity, but consume fewer resources than you would expect. When it comes to cities, density equals efficiency. Heating an apartment building that houses 100 people requires less energy than heating 100 separate farmhouses, for example. A subway can transport millions of people per day and requires far less energy than the cars it would take to move an equivalent number of commuters. “Many people, including myself at times, have said cities are going to be the saviors to our global environmental challenges because of these efficiencies,” Kennedy says.

But his data tell a slightly different story. Megacities, he found, produce a staggering 15 percent of the world’s GDP. But they also generate 13 percent of the world’s trash, and use 10 percent of its gasoline. If only about 7 percent of the people live there, that’s disproportionately high. (Water use appears impressively efficient, but remember that megacities generally don’t support agriculture.) What happened to all that urban efficiency?

It turns out that while density equals efficiency, “megacity” does not necessarily equal density. Many megacity dwellers live outside those hyper-efficient city centers, Kennedy explains. Look at New York—if you live in Manhattan or parts of Brooklyn and Queens, you’re probably getting around on the subway. But if you live in Westchester, New Haven, or Newark? You’re probably driving your car—maybe not into the city center, but around it. And there are a lot of you. That’s why New York is almost off the chart in its consumption of transportation fuel, despite all its great rail.

WIRED

But not all megacities consume as many resources as New York. Look at the ones clustered at the bottom end of transportation energy use: Mumbai. Karachi. Lagos. Cairo. Delhi. These are also some of the cities that use the least amount of electricity per capita. Unfortunately that’s not because their electrical grids are super-efficient. It’s because not everyone living there has electricity. “There’s huge disparities between the amount of resources being used between the wealthiest megacities and the poorest ones,” Kennedy says. In the latter, the resource inputs aren’t enough to support a basic standard of living for all citizens.

WIRED

Counterintuitively, this might change as these megacities grow. Energy use in megacities tends to grow faster than population does, Kennedy says. As their economies improve, so does their infrastructure, filling in the gaps that so many people previously fell into. Informal settlements become official neighborhoods as citizens demand representation and access to services (a process that has happened over and over in Mexico State).

So while developed-world megacities should consider reining in their gasoline and electricity use—or expanding center-city style efficient infrastructure to the ’burbs—growth (combined with smart policy) may be the answer to developing-world megacities’ woes. Which is good, because if one thing’s for sure it’s that megacities are growing, and they’re not going to stop.