The root of loneliness is too many people.
Loneliness in modern society is often more about being surrounded by too many people, not a lack of enough people. When you surround yourself with more people than you can know, it forces you to practice social isolation skills. You learn to walk past strangers without stopping to talk to them because you don't have enough time to get to know everyone. You learn to ignore people who need help, because there are too many of them to help. You learn that you need to always be on guard because the people around you have as little reason to care about you as you have to care about them.
In small communities people don't develop these self-isolation skills because they have the time, resources, and consideration to spare. So, everyone gets to know each other. In smaller groups, introverts are less likely to retreat from society and extroverts are less likely to treat others as disposable. This makes meaningful and enduring relationships easier to foster which do far more to prevent loneliness than just being around people. It also discourages anti-social behaviors when you are forced to learn from a young age that you can't just wash your hands of a person and move on with your life. Less anti-social behavior means you have less to fear from strangers which means its safer to get to know people you don't already know.
Counter intuitively, fewer people all builds up to having more and healthier human relationships.
Compartmentalize your township
In modern society, you can't just force a town to stay small forever, but you can grow it in a way that it functions like a cluster of small towns instead of like a modern city.
Disclaimer: Some users have commented that the following style of urban planning would not be pleasant for them individually to live in. This is an unavoidable consequence of any urban planning scheme. Whenever you try to force a society to a be a certain way, no matter how good your intentions, the answer will always be someone's dystopia. The one and only goal here is to minimize loneliness; so, please don't leave any more comments about the other shortcomings of this solution. I am well aware of the tradeoffs that would have to be made to make this system work.
Smaller Schools
The problems of modern loneliness often starts in schools. It used to be common that schools were smaller with only 1 class per grade level, and more grade levels under the same roof. Those 20-30 kids in your Kindergarten class would be the same 20-30 kids in your 1st-8th grade classes ... so good friendships would last and rivals were forced into the same space long enough to be forced to reconcile. Now, many schools have gotten so large that 80-90% of your class mates change every year as they shuffle around 100s of students per grade level. This teaches children that friends and rivals are temporary and that it is best not to care about either.
Smaller Neighborhoods
Every person has a certain nexus: an area of thier home town that they consider thier neighborhood. In a city or apartment complex, this means you are often sharing your nexus with 100s or even 1000s of people, and all of these nexuses overlap so you run into people from outside of your nexus in your space all the time. When your nexus becomes so big that most people are strangers, it means that you must develop a general since of mistrust of everyone you meet inside of your nexus in order to protect yourself. This mistrust is isolating because it means you can not just stop to get to know the people around you.
Many suburban areas have actually solved this problem by dividing up townships into sub-divisions and cul-de-sacs. When you live in a cul-de-sac, you could live in a large town or city, but when you step out your front door, it is always going to be the same 5-10 families out mowing thier lawns, playing in the street, checking thier mail, etc. This breeds familiarity and trust making it feel safe enough to stop and get to know those around you. Sub-divisions help too because they become larger compartmentalized communities which are still small enough that you can form at least a familiarity with those you live around, even if you don't know them all. And more importantly, the physical barriers they form help shape the nexus of everyone around you reducing the number of strangers you have to interact with, even if there are the same number of people within any given distance from you.
If true suburban living is not an option for everyone, apartment complexes can be similarly arranged. Keep the complexes small and compartmentalized. Maybe 50-100 units per complex arranged around a central courtyard, and small communal spaces in every walkway so that each group of 6-10 units has somewhere "out-front" to hang out with the neighbors. That way even if you must live in a more physically crowded space, you still get the small town experience.
Decentralized commercial/industrial zones
Most cities naturally develop a central business district. A place where businesses like to centralize to synergize off of the attractive power of nearby businesses. At first it starts off simple. An office opens up, then a restaurant opens up next to it to feed the office workers lunch, then a gas station next to that to refuel the people going in to work, and it just snowballs after that until you have clusters of 100 story buildings packed so densely with commerce that people can only even access it through inconvenient public transit systems which are again over crowded, scary, and full of strangers which discourages trust and relationship building. Instead, if your town has many small commercial zones interspaced by your subdivisions, then no one place would become so built up as to attract the preference of 10s or 100s of thousands of consumers all flocking to the same relatively tiny part of town.
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/wHvBh.png)
The above diagram is only meant to be conceptual. In execution, the exact ratios of houses : cul-de-sacs : subdivisions : communities may be very different, and probably won't be layed out in perfectly symmetrical circles like this... unless you want them to be. A more natural layout may look something more like Reno Nevada.
Finally: elemenatate housing that encourages living alone
Everything so far has been about not pushing too many people together, that said, the most important factor in not feeling lonely is not being completely alone. The most lonely population of people today regardless of how thier town is laid out are those who live by themselves. Many people will choose to live alone when it is the most economically and socially viable choice they have, but then find themselves feeling trapped in that loneliness.
The best way to solve for this through city planning is by restricting the construction of housing that makes it economically preferable to live alone. If your building codes require that all housing units must have at least 2 bedrooms, then single people would be forced to pay the same higher housing costs as family households. This would create an economic incentive for people who would otherwise choose to live alone, to instead choose to live with a room mate. Even if you could afford your own 2-bedroom house, you'd have that extra bedroom just sitting there burning a hole in your pocket; so, if life started feeling lonely, it would become a non-issue to just try to rent that extra bedroom out.
Is this Science or Speculation?
There is a lot of conflicting information. Some studies show only a weak correlation between suburban living and loneliness, whereas others show a very strong correlation.
According to This article which reviewed the data from the May 2021 American Perspectives Survey report, people in suburbs are only 2% less lonely than people in denser urban areas. However, according to this World Economic Forum report, overcrowding increases loneliness by up to 38%.
The reason that these studies show such different results has to do with thier methodology. When you ask a person "are you a lonely person?", the problem becomes "compared to what?" A person who is lonely 5% of the time may give the exact same answer as someone who is lonely 25% of the time because that amount of loneliness is normalized to both of them. So, a 1-time survey like the first one used above can't really be trusted to report loneliness; only people's perception of what normal amounts of loneliness is. The second study above was based off of ecological momentary assessments which randomly asked people how they feel right now. This is different because it has nothing to do with if you think those feelings are normal, just if you are having them. This makes the methodologies in studies that show a strong correlation objectively better that those that show a weaker one.
The study of loneliness in unban planning is also confounded by the fact that extremely high population densities can actually reduce loneliness too. In California for example, population density has driven up the price of housing so much that single people can usually not afford to live alone. So, while Californians experience a lot of the same community isolation as other densely populated places, they have the 2nd lowest % of single person households in the US, well below average divorce rates, and tend to score well when it comes to combating loneliness. So, there is also evidence that says that "encouraging" people not to live alone is also effective.