This guide is broken in three parts, first an overview of the stability mechanic, then how to keep your cities stable before unlocking the commons quarter and finally how to stay at 100% stability in your cities whilst building as many quarters as you like after you unlock the commons quarter.
Starting with a mechanic overview, think of stability as a tax on building quarters. Each quarter reduces the stability of your cities by 10 so, without any way of increasing your stability, you can only build 10 quarters in any given city. Once the stability in your cities goes to 0, you can only build quarters and buildings that boost your stability. There are a number of ways that you can generate stability:
- Holy sites produce around 20 stability by default which can be increased through things like wonders
- Tenets you can add to your religion
- Luxury resources
- Wonders produce a range of stability from 20 to 40, some wonders also produce extra bonuses to stability
- You can build infrastructure in your cities that give you stability
- The garrison quarter provides some stability that can be boosted with infrastructure
- The commons quarter, unlocked in the classical era technology Imperial Power, which provides stability based on adjacent quarters
You can also get various bonuses by picking certain civilizations.
Moving on to how to keep your cities stable before you unlock the commons quarter, use the above options, holy sites, adding stability tenets to your religion, building wonders and building infrastructure in your cities. I usually build whatever I want until the stability drops below 100%, which is when I switch to whichever one of the five options that is available to me at that point. If you run out of options, focus on building things other than quarters, such as armies or infrastructure. I recommend against building too many garrisons because they take up valuable land and produce a lot less stability that commons quarters.
Now discussing how to basically build as many quarters/ districts you want whilst keeping your cities 100% stable, the commons quarter produces 5 stability for each adjacent farmers, makers, research or market quarter. Therefore, without any bonuses, you need 2 commons quarters to be adjacent to every farmers, research, industry or market quarter to negate the stability impact. This can be achieved by building overlapping hexagons of quarters with the commons quarter in the middle. Depending on the terrain, sometimes you have to be a bit inefficient with the commons quarters to ensure that you keep 2 commons quarter next to any of the other quarters.

So, in summary, before unlocking the commons quarter build whatever quarters you want until you go below 100% stability and then switch to one of the options that provide you with stability before resuming building whatever you want. Once you unlock the commons quarter, keep two commons quarter next to each other quarter and you can build as many quarters in a city as you want and still stay at 100% stability.