In the heart of Manila's vast North Cemetery, the largest graveyard in the capital of the Philippines, Ricky Baking is hunched over a tomb with a hammer and chisel. After several determined blows, the lid cracks into three pieces. He opens the rotten coffin to reveal the skeleton of a 65-year-old man, dressed in his burial suit and shoes. Baking steps into the tomb with bare feet, and reaches for the bones.

This isn't a grave robbery – it's an eviction. Like everywhere else in Manila, the North Cemetery has run out of space. Up to 80 funerals take place here every day, and demand for plots is so high most people can only afford to rent tombs. If your relatives fail to keep up the payments, another body will take your place. It's Baking's job to clear this grave so another coffin can be lowered into it later this afternoon. He's done this so often it's almost mundane to him.

Land is precious in Manila, and people are prepared to endure incredible circumstances to claim their own piece. Baking's family is one of hundreds that have set up home in the cemetery, jostling for space with the dead. "It's much better living here than in a shanty town," he assures me as we clamber over densely-packed powder pink and blue tombs on the way to his home. "It's much more peaceful and quiet."

The crypt where his family of seven sleeps is barely bigger than a garden shed, but it's furnished with every modern convenience: there's a fridge, a DVD player, electric fans and a built-in toilet. His youngest daughter was a little frightened when they moved here four years ago, he says, but they now find it easy to forget the body buried beneath its floor. In a city with too many people, this is a decent place to live.

The world is facing an overpopulation crisis. In 40 years time, if current growth rates continue, the number of people on the planet will be almost one and a half times what it is today, rising from 6.8 billion to 9.2 billion by 2050. As population increases, so does competition for basic resources – land, food, water and fuel – as well as the threat of environmental devastation and endemic disease. Our numbers are going to be unsustainable within a few years.

Most of the 10,000 babies born every hour are going to grow up in urban settlements: more than half the world's population now live in cities, and that will rise to 70% by 2050. Megacities – with more than 10 million inhabitants – are springing up across the globe, particularly in developing countries. In 1985, there were only nine megacities Today, there are 26.

But as we brace ourselves for the future challenges posed by overpopulation, the residents of Manila are already living with them. This is the city where the statistics come alive. Greater Manila is home to 20 million people, rising by another quarter of a million every year. It's a place of great economic extremes, and space and privacy are luxuries only afforded to Manila's wealthy elite. A third of Manilans live cheek by jowl in makeshift settlements on any bit of spare land – under bridges, next to railway lines, beside flood defences as well as cemeteries. These are ordinary people, often with reasonably paid jobs, who can only afford to live in battery conditions if they want to stay in the city.

Overcrowding is a fact of life from cradle to grave in Manila. At the government-run Jose Fabella maternity hospital, four mothers and their newborns share each bed. On the morning I visit, 133 babies have already been born since midnight in one ward alone. It's desperately hot and the mothers are fanning their babies with whatever they can find. The ward is well-equipped, but running at double capacity. There are simply too many mothers calling on its resources.

"Looking after the welfare of so many people is quite a challenge," says Elisa Navarro, the head nurse. "We have to do regular ward checks to make sure none of the mothers are sleeping on the babies and suffocating them." I can see how easily it would be for this to happen – most of the women are exhausted from labour and almost unaware of the seven other people in their bed. But the mothers tell me they're used to it: at home their entire family will sleep together on a single mattress, which can often mean sharing a bed with eight or nine other people.

The Parapina family live in Baseco, a shanty town of just over half a square kilometre that's home to 90,000 people. Jennifer and Manuel have seven children, aged eight to 17 and all nine share a shack that's no more than three metres across. There's no space for tables, chairs or a mattress – so when night falls, the family put bedding down on the floor and lie side by side together, like sardines.

Jennifer and Manuel earn enough money to clothe and feed their enormous family, and to furnish their home with electric fans and a television set, but the only way they can afford a place in the city is to build it themselves on public land, out of whatever wood and corrugated iron they can scavenge. They've lost four previous homes to the fires that often rage through Baseco. It's easy to see why: the rooftops are draped in thick tangles of cables, illegally tapping electricity from Manila's central supply.

We sit cross-legged on the bare floor, with Jennifer's youngest five children gathered around her. "We never planned to have so many," Jennifer smiles bashfully, "but I think of our children as a blessing. They're going to look after us when we're older." In a country with a weak social care system, a large family is your insurance policy. It's a reason why so many people across the developing world reconcile themselves to the poverty that can come with large families.

Jennifer is only 36, but by the time she was 28 she'd already been pregnant nine times. Contraception has long been taboo in the Philippines – this is a Catholic country and successive governments have refused to promote sex education and contraception for fear of losing the Catholic vote. The Parapinas count themselves as observant Catholics, but it wasn't fear of hellfire that stopped Jennifer from planning her family – it was lack of information. When a local charity began offering free advice and birth control in Baseco a few years ago, she chose to be on a long-term contraception, and the Parapina family finally stopped growing.

Contagious diseases spread fast in Baseco. Jennifer has been living with tuberculosis for two years, but she's tells me about it in the matter-of-fact manner of someone who accepts serious illness as a normal part of life. Pneumonia, measles, cholera and dengue fever claim thousands of lives a year in Manila's most built-up areas. But this isn't enough to stop the city's population growing.

Jennifer's children say they'll show me around the shanty town. Baseco has grown up around a sea wall near the city centre that's supposed to protect Manila from flooding. Typhoon Ondoy killed hundreds in the capital last year but people are still building homes right against the flood defences here. The sea wall itself has been turned into the town's unofficial high street, with grocery stores, snack bars and even funeral parlours setting up stall right next to the water.

We arrive at the filthiest beach I have ever seen, strewn with household waste, plastic bags, polystyrene, old shoes, bricks and car tyres, with the strong, acrid smell of urine – a nightmare inversion of the Philippine beach on the front of my guidebook. Princess Parapina, 15, says this is the place where the children play. Most of the rubbish is washed up from the sea: the beach lies close to the mouth of the notorious Passig River, Manila's unofficial sewer and garbage chute that cuts the capital in two, which was declared biologically dead in the 1990s.

The people of Baseco add to the rubbish, of course. There's no sanitation in the shanty town and people have the choice of either coming down to this beach to go to the toilet or using a plastic bag in their homes. But even space on land as polluted as this is precious and there are houses built right up along the water's edge, wherever the ground is solid enough to support a shack.

The Parapina children rarely get the chance to play together because of the way the public school system works in Manila. There are 6,000 children at the local primary, so they have to go to school in shifts, staggered throughout the day, with classes starting at dawn for some. There are one thousand nine-year-olds in Mark Anthony Parapina's year alone, taught in three separate batches, with six classrooms of children in each shift.

Baseco Elementary has everything you'd expect in a modern school – there's a library, plenty of text books, posters and artwork on the walls – but the main resource teachers lack is sufficient time with their students. Mark Anthony's teacher, Evangeline Castro, tells me it's an uphill struggle. "The four hours we get with each class isn't enough to teach them well," she says. "We're really rushing to pack in everything we can into those four hours." No matter how hard she works, she'll only be able to give her pupils half an education.

The city's wealthy residents have largely been able to buy themselves out of Manila's worst problems. They live in spacious gated communities, they go to work in glass tower blocks in the city's gleaming financial district and they send their children to elite private schools where they'll only have to share their teachers with a few hundred or so others. But even the richest can't avoid the traffic. With millions of cars on the road, drivers spend an average of 1,000 hours every year stuck in jams, and even when cars are moving, they crawl at less than 10km an hour. Manila's municipal government has tried to ease the congestion by limiting which cars can be driven on certain days of the week, according to the numbers on their plates. But those who can afford it have simply bought a second car so they can stay on the road, driving different cars on different days.

Manila's wealth is the prime reason the city's population is exploding. If you want a piece of development and prosperity in the Philippines, you have to come to the capital. Rural poverty has caused thousands of Filipino people to flood into Manila every year from the countryside in search of their fortune. They arrive to find few jobs and nowhere to live – but this still isn't enough to make them return home.

Bai Warda's family is one of 300 who have set up home under a bridge in Quiapo, near the centre of town. She moved here from Mindanao, an island in the south of the country and she's brought up four children on the banks of the stagnant San Miguel waterway. From a distance the settlement looks incredibly ramshackle, made up of plywood shacks precariously balanced on stilts in the sewage-filled river, but close up it's clear that this is a functioning village with its own electricity supply, restaurants and a barber. Bai Warda has been running the local grocery store here for nearly 30 years.

"Most of the people who live here weren't born in Manila. We come from all over the country," she tells me. "I came here because I thought we'd be able to get jobs and better living conditions in the city." I wonder how desperate life must have been at home for this makeshift community to be a better alternative. "I'd never go back to Mindanao – there's nothing for us there," she replies. "I couldn't provide for my family's future if I went back."

It's tempting to think of Manila's overpopulation problem as extraordinary and exceptional. But as global population explodes, and wealth is increasingly concentrated in sprawling cities, Manila is an example of what urban centres all over the world may look like in the not too distant future. And as cities in developing countries become overwhelmed by their population, their inhabitants will have even more reason to migrate to the developed world. The planet is running out of space. Perhaps we will all need the resourcefulness and resilience of Manila's residents if we're going to continue living on it.

• Jenny Kleeman's film for Unreported World: The City with Too Many People, will be broadcast on Friday 15 October at 7.30pm on Channel 4