Bare Minimum
1. Get your defensive weapons inside walls.
2. Get your other important stuff inside walls
In a war base, town hall (th) is always important. See War Defense.
In your village,
3. Use Multiple Rings
Once you hit town hall level 5 (th5), get your most important things inside two rings of walls (not to be confused with double walls). That would include your splash weapons (wizard towers and mortar), and your storages in your village and your town hall in your war base. The th5 and 6 layouts shown on the Village and Base page have two full rings of walls, with the most important stuff in the inner ring.
2. Get your other important stuff inside walls
In a war base, town hall (th) is always important. See War Defense.
In your village,
- if trophies are more important to you, get your th (town hall) inside walls,
- if resources are more important to you, get your storages inside walls and your th outside the walls (also called a farming base)
3. Use Multiple Rings
Once you hit town hall level 5 (th5), get your most important things inside two rings of walls (not to be confused with double walls). That would include your splash weapons (wizard towers and mortar), and your storages in your village and your town hall in your war base. The th5 and 6 layouts shown on the Village and Base page have two full rings of walls, with the most important stuff in the inner ring.
4. Use buffer buildings.
Put your less important stuff outside walls but in range of as many weapons as possible. These are called buffer buildings.
Why use buffer buildings? Indiscriminate units (units without a favorite target: barbarians, archers, wizards, etc.) will attack whatever is closest to them. So, if you have a bunch of collectors and mines outside your walls but in range of weapons, they will spend time hacking at those things (while taking hit points) before getting to the goodies inside the walls.
5. Compartmentalize
If you have walls left over, compartmentalize your important stuff. (or put each unit in a "cell". Example: a cannon defensive unit with walls all the way around it.)
When the enemy gets through your outer wall it is better if they don't have free reign over all your goodies. If they have to break through an extra wall to get to that next archer tower, for example, they will spend more time taking hit points before they get to it.
6. Don't rush your base.
Don't level up your town hall before upgrading other buildings and your units. I prefer to max out walls, defenses, army camps, and troop levels before upgrading town hall. You don't absolutely have to do that, but if your town hall gets too far ahead of other stuff, your base will be declared 'rushed' and you will not be allowed to stay in the clan. Here are some specifics on rushing.
Don't level up your town hall before upgrading other buildings and your units. I prefer to max out walls, defenses, army camps, and troop levels before upgrading town hall. You don't absolutely have to do that, but if your town hall gets too far ahead of other stuff, your base will be declared 'rushed' and you will not be allowed to stay in the clan. Here are some specifics on rushing.