Two bodyguards trotted behind Enrique Peñalosa, their pistols jostling in holsters. There was nothing remarkable about that, given his profession – and his locale. Peñalosa was a politician on yet another campaign, and this was Bogotá, a city with a reputation for kidnapping and assassination. What was unusual was this: Peñalosa didn't climb into the armoured SUV. Instead, he hopped on a mountain bike. His bodyguards and I pedalled madly behind, like a throng of teenagers in the wake of a rock star.

A few years earlier, this ride would have been a radical and – in the opinion of many Bogotáns – suicidal act. If you wanted to be assaulted, asphyxiated by exhaust fumes or run over, the city's streets were the place to be. But Peñalosa insisted that things had changed. "We're living an experiment," he yelled back at me. "We might not be able to fix the economy. But we can design the city to give people dignity, to make them feel rich. The city can make them happier."

I first saw the Mayor of Happiness work his rhetorical magic back in the spring of 2006. The United Nations had just announced that some day in the following months, one more child would be born in an urban hospital or a migrant would stumble into a metropolitan shantytown, and from that moment on, more than half the world's people would be living in cities. By 2030, almost 5 billion of us will be urban.

Peñalosa insisted that, like most cities, Bogotá had been left deeply wounded by the 20th century's dual urban legacy: first, the city had been gradually reoriented around cars. Second, public spaces and resources had largely been privatised. This reorganisation was both unfair – only one in five families even owned a car – and cruel: urban residents had been denied the opportunity to enjoy the city's simplest daily pleasures: walking on convivial streets, sitting around in public. And playing: children had largely disappeared from Bogotá's streets, not because of the fear of gunfire or abduction, but because the streets had been rendered dangerous by sheer speed. Peñalosa's first and most defining act as mayor was to declare war: not on crime or drugs or poverty, but on cars.

He threw out the ambitious highway expansion plan and instead poured his budget into hundreds of miles of cycle paths; a vast new chain of parks and pedestrian plazas; and the city's first rapid transit system (the TransMilenio), using buses instead of trains. He banned drivers from commuting by car more than three times a week. This programme redesigned the experience of city living for millions of people, and it was an utter rejection of the philosophies that have guided city planners around the world for more than half a century.

In the third year of his term, Peñalosa challenged Bogotáns to participate in an experiment. As of dawn on 24 February 2000, cars were banned from streets for the day. It was the first day in four years that nobody was killed in traffic. Hospital admissions fell by almost a third. The toxic haze over the city thinned. People told pollsters that they were more optimistic about city life than they had been in years.

Colombian students ride their bicycles during 'No car day' in Bogota. The day-long ban on all private car traffic on the city's streets forces residents to use public transportation or bicycles to get to and from work. Photograph: Jose Miguel Gomez/Reuters

One memory from early in the journey has stuck with me, perhaps because it carries both the sweetness and the subjective slipperiness of the happiness we sometimes find in cities. Peñalosa, who was running for re-election, needed to be seen out on his bicycle that day. He hollered "Cómo le va?" ("How's it going?") at anyone who appeared to recognise him. But this did not explain his haste or his quickening pace as we traversed the north end of the city towards the Andean foothills. It was all I could do to keep up with him, block after block, until we arrived at a compound ringed by a high iron fence.

Boys in crisp white shirts and matching uniforms poured through a gate. One of them, a bright-eyed 10-year-old, pushed a miniature version of Peñalosa's bicycle through the crowd. Suddenly I understood his haste. He had been rushing to pick up his son from school, like other parents were doing that very moment up and down the time zone. Here, in the heart of one of the meanest, poorest cities in the hemisphere, father and son would roll away from the school gate for a carefree ride across the metropolis. This was an unthinkable act in most modern cities. As the sun fell and the Andes caught fire, we arced our way along the wide-open avenues, then west along a highway built for bicycles. The kid raced ahead. At that point, I wasn't sure about Peñalosa's ideology. Who was to say that one way of moving was better than another? How could anyone know enough about the needs of the human soul to prescribe the ideal city for happiness?

But for a moment I forgot my questions. I let go of my handlebars and raised my arms in the air of the cooling breeze, and I remembered my own childhood of country roads, after-school wanderings, lazy rides and pure freedom. I felt fine. The city was mine. The journey began.

Is urban design really powerful enough to make or break happiness? The question deserves consideration, because the happy city message is taking root around the world. "The most dynamic economies of the 20th century produced the most miserable cities of all," Peñalosa told me over the roar of traffic. "I'm talking about the US Atlanta, Phoenix, Miami, cities totally dominated by cars."

Red Transmilenio buses pull into the Museum of Gold station in front of the 16th century Iglesia de San Francisco, Bogota's oldest restored church. Photograph: John Coletti/Getty Images

If one was to judge by sheer wealth, the last half-century should have been an ecstatically happy time for people in the US and other rich nations such as Canada, Japan and Great Britain. And yet the boom decades of the late 20th century were not accompanied by a boom in wellbeing. The British got richer by more than 40% between 1993 and 2012, but the rate of psychiatric disorders and neuroses grew.

Just before the crash of 2008, a team of Italian economists, led by Stefano Bartolini, tried to account for that seemingly inexplicable gap between rising income and flatlining happiness in the US. The Italians tried removing various components of economic and social data from their models, and found that the only factor powerful enough to hold down people's self-reported happiness in the face of all that wealth was the country's declining social capital: the social networks and interactions that keep us connected with others. It was even more corrosive than the income gap between rich and poor.

As much as we complain about other people, there is nothing worse for mental health than a social desert. The more connected we are to family and community, the less likely we are to experience heart attacks, strokes, cancer and depression. Connected people sleep better at night. They live longer. They consistently report being happier.

There is a clear connection between social deficit and the shape of cities. A Swedish study found that people who endure more than a 45-minute commute were 40% more likely to divorce. People who live in monofunctional, car‑dependent neighbourhoods outside urban centres are much less trusting of other people than people who live in walkable neighbourhoods where housing is mixed with shops, services and places to work.

A couple of University of Zurich economists, Bruno Frey and Alois Stutzer, compared German commuters' estimation of the time it took them to get to work with their answers to the standard wellbeing question, "How satisfied are you with your life, all things considered?"

Their finding was seemingly straightforward: the longer the drive, the less happy people were. Before you dismiss this as numbingly obvious, keep in mind that they were testing not for drive satisfaction, but for life satisfaction. People were choosing commutes that made their entire lives worse. Stutzer and Frey found that a person with a one-hour commute has to earn 40% more money to be as satisfied with life as someone who walks to the office. On the other hand, for a single person, exchanging a long commute for a short walk to work has the same effect on happiness as finding a new love.

Daniel Gilbert, Harvard psychologist and author of Stumbling On Happiness, explained the commuting paradox this way: "Most good and bad things become less good and bad over time as we adapt to them. However, it is much easier to adapt to things that stay constant than to things that change. So we adapt quickly to the joy of a larger house, because the house is exactly the same size every time. But we find it difficult to adapt to commuting by car, because every day is a slightly new form of misery."

The sad part is that the more we flock to high‑status cities for the good life – money, opportunity, novelty – the more crowded, expensive, polluted and congested those places become. The result? Surveys show that Londoners are among the least happy people in the UK, despite the city being the richest region in the UK.

'Stop moving long enough, and your muscles will atrophy. Bones will weaken. Blood will clot.' Illustration: Francesco Bongiorni for the Guardian

When we talk about cities, we usually end up talking about how various places look, and perhaps how it feels to be there. But to stop there misses half the story, because the way we experience most parts of cities is at velocity: we glide past on the way to somewhere else. City life is as much about moving through landscapes as it is about being in them. Robert Judge, a 48-year-old husband and father, once wrote to a Canadian radio show explaining how much he enjoyed going grocery shopping on his bicycle. Judge's confession would have been unremarkable if he did not happen to live in Saskatoon, Saskatchewan, where the average temperature in January hovers around -17C. The city stays frozen and snowy for almost half the year. Judge's pleasure in an experience that seems slower, more difficult and considerably more uncomfortable than the alternative might seem bizarre. He explained it by way of a story: sometimes, he said, he would pick up his three-year-old son from nursery and put him on the back seat of his tandem bike and they would pedal home along the South Saskatchewan river. The snow would muffle the noise of the city. Dusk would paint the sky in colours so exquisite that Judge could not begin to find names for them. The snow would reflect those hues. It would glow like the sky, and Judge would breathe in the cold air and hear his son breathing behind him, and he would feel as though together they had become part of winter itself.

Drivers experience plenty of emotional dividends. They report feeling much more in charge of their lives than public transport users. An upmarket vehicle is loaded with symbolic value that offers a powerful, if temporary, boost in status. Yet despite these romantic feelings, half of commuters living in big cities and suburbs claim to dislike the heroic journey they must make every day. The urban system neutralises their power.

Driving in traffic is harrowing for both brain and body. The blood of people who drive in cities is a stew of stress hormones. The worse the traffic, the more your system is flooded with adrenaline and cortisol, the fight-or-flight juices that, in the short-term, get your heart pumping faster, dilate your air passages and help sharpen your alertness, but in the long-term can make you ill. Researchers for Hewlett-Packard convinced volunteers in England to wear electrode caps during their commutes and found that whether they were driving or taking the train, peak-hour travellers suffered worse stress than fighter pilots or riot police facing mobs of angry protesters.

But one group of commuters report enjoying themselves. These are people who travel under their own steam, like Robert Judge. They walk. They run. They ride bicycles.

Why would travelling more slowly and using more effort offer more satisfaction than driving? Part of the answer exists in basic human physiology. We were born to move. Immobility is to the human body what rust is to the classic car. Stop moving long enough, and your muscles will atrophy. Bones will weaken. Blood will clot. You will find it harder to concentrate and solve problems. Immobility is not merely a state closer to death: it hastens it.

Robert Thayer, a professor of psychology at California State University, fitted dozens of students with pedometers, then sent them back to their regular lives. Over the course of 20 days, the volunteers answered survey questions about their moods, attitudes, diet and happiness. Within that volunteer group, people who walked more were happier.

The same is true of cycling, although a bicycle has the added benefit of giving even a lazy rider the ability to travel three or four times faster than someone walking, while using less than a quarter of the energy. They may not all attain Judge's level of transcendence, but cyclists report feeling connected to the world around them in a way that is simply not possible in the sealed environment of a car, bus or train. Their journeys are both sensual and kinesthetic.

In 1969, a consortium of European industrial interests charged a young American economist, Eric Britton, with figuring out how people would move through cities in the future. Cities should strive to embrace complexity, not only in transportation systems but in human experience, says Britton, who is still working in that field and lives in Paris. He advises cities and corporations to abandon old mobility, a system rigidly organised entirely around one way of moving, and embrace new mobility, a future in which we would all be free to move in the greatest variety of ways.

"We all know old mobility," Britton said. "It's you sitting in your car, stuck in traffic. It's you driving around for hours, searching for a parking spot. Old mobility is also the 55-year-old woman with a bad leg, waiting in the rain for a bus that she can't be certain will come. New mobility, on the other hand, is freedom distilled."

A row of Velib rental bicycles are parked at the rue de La Harpe in Paris. Dozens of cities have now dabbled in shared bike programmes, including London, Montreal, Melbourne and New York Photograph: Horacio Villalobos/EPA

To demonstrate how radically urban systems can build freedom in motion, Britton led me down from his office, out on to Rue Joseph Bara. We paused by a row of sturdy-looking bicycles. Britton swept his wallet above a metallic post and pulled one free from its berth. "Et voilà! Freedom!" he said, grinning. Since the Paris bike scheme, Vélib', was introduced, it has utterly changed the face of mobility. Each bicycle in the Vélib' fleet gets used between three and nine times every day. That's as many as 200,000 trips a day. Dozens of cities have now dabbled in shared bike programmes, including Lyon, Montreal, Melbourne, New York. In 2010, London introduced a system, dubbed Boris Bikes for the city's bike-mad mayor, Boris Johnson. In Paris, and around the world, new systems of sharing are setting drivers free. As more people took to bicycles in Vélib's first year, the number of bike accidents rose, but the number of accidents per capita fell. This phenomenon seems to repeat wherever cities see a spike in cycling: the more people bike, the safer the streets become for cyclists, partly because drivers adopt more cautious habits when they expect cyclists on the road. There is safety in numbers.

So if we really care about freedom for everyone, we need to design for everyone, not only the brave. Anyone who is really serious about building freedom in their cities eventually makes the pilgrimage to Copenhagen. I joined Copenhagen rush hour on a September morning with Lasse Lindholm, an employee of the city's traffic department. The sun was burning through the autumn haze as we made our way across Queen Louise's Bridge. Vapour rose from the lake, swans drifted and preened, and the bridge seethed with a rush-hour scene like none I have ever witnessed. With each light change, cyclists rolled toward us in their hundreds. They did not look the way cyclists are supposed to look. They did not wear helmets or reflective gear. Some of the men wore pinstriped suits. No one was breaking a sweat.

Lindholm rolled off a list of statistics: more people that morning would travel by bicycle than by any other mode of transport (37%). If you didn't count the suburbs, the percentage of cyclists in Copenhagen would hit 55%. They aren't choosing to cycle because of any deep-seated altruism or commitment to the environment; they are motivated by self-interest. "They just want to get themselves from A to B," Lindholm said, "and it happens to be easier and quicker to do it on a bike."

The Bogotá experiment may not have made up for all the city's grinding inequities, but it was a spectacular beginning and, to the surprise of many, it made life better for almost everyone.

The TransMilenio moved so many people so efficiently that car drivers crossed the city faster as well: commuting times fell by a fifth. The streets were calmer. By the end of Peñalosa's term, people were crashing their cars less often and killing each other less frequently, too: the accident rate fell by nearly half, and so did the murder rate, even as the country as a whole got more violent. There was a massive improvement in air quality, too. Bogotáns got healthier. The city experienced a spike in feelings of optimism. People believed that life was good and getting better, a feeling they had not shared in decades.

Bogotá's fortunes have since declined. The TransMilenio system is plagued by desperate crowding as its private operators fail to add more capacity – yet more proof that robust public transport needs sustained public investment. Optimism has withered. But Bogotá's transformative years still offer an enduring lesson for rich cities. By spending resources and designing cities in a way that values everyone's experience, we can make cities that help us all get stronger, more resilient, more connected, more active and more free. We just have to decide who our cities are for. And we have to believe that they can change.

• This is an edited extract from Happy City: Transforming Our Lives Through Urban Design, by Charles Montgomery, published by Penguin at £16.99.

• This article was edited on 4 November 2013, to make clear that it is an edited extract.