Well, the following summarizes how I do it, and is fairly generic demographics for my campaign world.
A typical human town consists of about 120 wooden homes clustered together along somewhat but not entirely regular dirt streets, each home having a small garden plot of around 1/5th of an acre which is used for herbs, vegetables, chicken coups, dove cotes, bee hives and the like. The whole encompasses about 30 acres and is surrounded by walled off (by stone fences or hedges) fields of various sizes which serve as pastureland for larger animals and as fields for food crops – chiefly grains and pulses, but may include potatoes, yams, turnips, beets, and other root vegetables or depending on the climate orchards or vinyards. This farmland covers a further 600 acres, and may have a number of outlying homes, so that the whole covers about 1 square mile.
Towns are typically constructed along rivers or major roads or (quite often) both, as human communities are generally not intended to be self-sufficient but part of a much larger trade network with other settlements. The nearest towns are generally eight miles away, with the intervening country side being composed of scattered hamlets and villages of 10-40 homes and manors of wealthier freemen and nobles. These (either villages or manors) generally exist at rates of about 1 per 2 square miles with correspondingly smaller fields of crops, with the remaining land being forested to provide timber, firewood, forage for pigs, and hunting. A generally sixty-four square mile territory around a human town will have about 6000 to 7000 inhabitants, but perhaps twice this number if the land is very lush and highly arable (or half that if it is wild and barren). This is vastly higher densities of habitation and larger populations than is achieved by any other fantasy species, for humans are the acknowledged masters of cultivation and food production.
Homes are generally two-story (often with an attic or loft as well) with 1-2 rooms per floor (depending on affluence). Homes will be made usually of heavy timber construction with spaces filled with smaller planks and plaster. Upper stories often slightly overhang the lower stories, both for tax evasion and defensive purposes. Roofs are tiled with ceramic, shingle, or slate to be water and fireproof. About 10% of homes will (material availability permitting) be constructed of stone or brick. First floors are generally at least partially flagged with stone, and there will always be a fireplace and chimney of stone or brick. Outlying homes of poorer families (30%) may have thatched roofs and fill of wattle and daub and first floors of packed earth and even simple hearths in the middle of the floor rather than stone chimneys, but these money saving items are likely to be forbidden within the town proper as fire hazards and eye sores unsuitable to the town’s dignity.
Exterior doors will be of thick timber, often reinforced with iron. Locks are relatively rare and found only on the homes of the wealthier sort, but all homes will have bolts and bars to fasten doors closed securely from the inside. Windows are on the lower story always have a stout lattice of wood or iron to prevent entry, and all windows will be equipped with heavy wooden shutters with can be closed and barred from the inside. Glass is relatively rare and generally found only in the wealthier homes, with cloth or vellum or paper serving in less wealthy homes to screen out insects or wind while at least letting in some light.
Most first floors will either be the shops of craftsman or small barns holding 1-2 milking cows or other livestock, which can be taken out to pasture in the morning and brought back in the evening. The upper story serves as living area for the family, and is generally reached by a ladder. This ladder is brought up through a trapdoor to the upper floor at night, and the trapdoor securely bolted and fastened from the inside. Many families, especially those with shops, are likely to leave behind on the first floor a hound to serve as guard and watch.
Each home holds an extended family of 4-15 individuals, usually comprising three or more generations, with a patriarch and spouse, his heir and their spouse, grandchildren of various ages, and such relations as aunts, sisters or cousins which are unable for whatever reason to support themselves plus a servant or apprentice or two, who are themselves often cousins or relations by marriage to more distant family members. There will typically be 1-3 men of fighting age per home, and some weapons stored away such as a crossbow, spear, or short sword. Everyone else will equip themselves with daggers, truncheons, hatchets, and such weapons as can be improvised from tools.
Such a town will generally employ eight to ten professional watchmen to serve as sentries and peacekeepers. Each will be a character of 2nd-4th level with various skills useful to a role as sentry, soldier, and detective. Such a town will have at the least a watchtower (and perhaps two) so as to observe the comings and goings along the road and river, and over the broad fields that sustain the community, equipped with a bell or similar device to sound alarm if something seems amiss. Watchmen, and the community in general depend heavily on the protection and aid of large trained hounds, bred for this purpose. There will be one such hound for each watchmen and 1-3 for each outlying home, and one for most homes in the community (especially wealthier ones) so as to aid in the securing of valuables (as previously mentioned). The watch will be provided with the city with such items as flaming oil, holy water, silver tipped bolts or arrows, and other valuable items to defend the city in the event of non-human attackers. The watch will have close relationships with the city cults, hedge wizards, undertakers, rat catchers, lumberjacks, and other individuals with experience handling such dangerous pests as plague magical realms, and will likely also be able to call upon the assistance of nearby knights known to be brave in the face of such dangers and willing to risk life and blood against such foes.
In the event of a general attack on the town, each household will as best as they can attempt to hole up in their home, perhaps harassing any visible attacker with missile fire from upper story windows or accessible rooftops, or hurling such improvised weapons as pots of boiling water or bed pans as may be devised. Between 40 and 100 men of the city, having spent three to six weeks of each year in training to gain minimal proficiency at arms, form the core militia of the town and are called the Guard. Normally they work at other trades, but are hired by the city from time to time to assist the watch in maintaining order, inspecting travelers passing through, or keeping watch during fair days. These men possessing gambeson, shield, spear and like such equipment will attempt to gather at a prearranged place in order to assess the situation and prepare to repel the invaders. They will be led by their own captain, the professional watch, as well as such nobles that live in the city who have martial bearing. Once assembled, they will move to deal with concentrations of attackers, and while on the march make the assessment of whether to have citizens along the route remain in their homes or rally to them to bolster their ranks.
For every such town there will be 1-3 hedge wizards of 2-5th level of ability who in extremis will serve in the defense of the city, though they are relatively unlikely to be well prepared with spells of the combat sort or have invested in such items as adventurers take for granted, they do have some magical potency and will certainly know some spells of a defensive sort or magical counter-measures against such things as illusions, invisibility, and so forth.
Likewise, for every such town there will be 6-8 priests of 2-5th level of ability who lead the major cults of the city and serve in such shrines and temples as such a small town can afford. These priests can also array themselves for battle to some extent, and there is a good chance that the most successful cult or cults have in their employ 1-4 Templars who serve the priest and temple as guardians and general roustabouts, and each of these will generally be a fighting man of 1st to 3rd level.
In general, human communities do not rely on static defenses and generally, unless they are the sort of border towns described below, do not expect to be self-sufficient in defense. Instead, towns regularly communicate to each other about threats through messengers and reports from outlying villages and hamlets. Instead of attempting to make an invincible defense at all points, humans tend to aggressively counter-attack, pursue or head-off any threat by mustering militia, knights, and others from a force of the willing and sending it to aid any area known to be threatened. So from the manors surrounding the town, generally some 20 or so knights each a mounted fighting man of 2nd-5th level can be summoned, each accompanied by a squire (who is often an eldest son or nephew) of 1st-3rd level ability (but never higher than his knight master) along with 1-6 men-at arms per knight (again, often cousins and relatives of the knight). A town may be able to call upon the forces of 4-8 neighboring towns who will readily lend aid if they do not have their own more immediate security concerns, so a force of bandits or marauders if their movements are observed and reported, can expect to quite soon be facing an angry force of around 120 knights, 120 squires, 400 men-at-arms, and 600 militia infantry supported by spell-casters. Such a force can readily be maintained for short periods since at all times it is not more than a day or day and a half journey from its base of operations and so logistics, while serious are not excessively burdensome. And this regional force is insufficient, then you can soon expect a national force to arrive with better equipment, and more powerful spell-casters in support.
Professional messenger services between towns are fairly common, consisting of skilled riders with horses who can be sent to outlying communities or neighboring towns. These are maintained either as a business, or by associations of guilds, or by the sovereign of the land themselves as a community service. In wilder lands, such messengers are often functionally (and collectively) skilled light cavalry.
This situation prevails through most human occupied lands, but in less settled and tamed areas, or within two or three marches of borders between nations, towns tend to be walled strongholds. Such towns cannot afford the space for garden plots which must perforce then all lie outside the city, but have buildings that adjoin each other and are densely packed into an area of 15 acres or less, with a curtain wall 8 to 10 feet wide and 15 to 20 feet high encircling the city (a distance of about a half-mile) and fortified by 12 to 16 towers and two gate houses, with two watch towers of stone rising above the ramparts. At the least, wooden hoardings will be maintained to provide full protection to defenders, but it is more common that hoardings of stone and tile made as permanent features of such fortifications. About half of the guard of such a town (20-50 men) are permanently employed to assist the watch In patrolling the wall and maintaining security in the town, and will have a captain among them who is himself a 2nd-5th level fighting man – often a mercenary officer now leading a more settled life or a landless knight who has found such employment honorable. Such guards will have mail and shield, and be equipped with the best selection of arms. A good portion of such towns if they are truly on the border will also be garrison towns, with a small castle attached to the walls of the town holding a garrison of 40-60 additional fighting men with their own captain. Half of these troops will be mounted so as to provide patrols in the lands about the town. These garrisons and their fortifications are paid for by the King (or other ruler) or some great lord such as a Duke or Marquise to ensure the security of their demesnes.
Likewise, those manors on the border will be less mere homes and more fortified keeps, some even having a bailey in order to protect the knight’s servants and his livestock.
None of these fortifications are intended in of themselves to provide security. Rather they deter weaker attackers while providing a delay and threat to more serious enemies until the full forces of the region can be brought to bear.
Or course, such fortifications are expensive, and so taxation in such towns is commensurately higher (often double) especially on travelers wishing to lodge in or pass through the town. Quality of life on a daily basis also suffers compared to more open towns where land is less at a premium and where people may freely come and go without passing through guarded gates. There is therefore often a tendency to neglect the maintenance of such defenses in times of peace and when significant monstrous attackers have not assailed the town in generations. During such periods, hamlets and villages often sprout up outside the very gates of the town, taking advantage of the cheaper and more livable land compared to the denser town within the walls. Sometimes such laxity is reward for long periods. At other times the dangers of the world penalize such a casual disregard of security in the harshest manner. A significant portion of the politics of these walled towns therefore consists of lobbying various lords and rulers to subsidize the town’s defenses so that they can lower taxes and become more attractive as places of business and settlement, without having to cut corners on their own defense which they may later have cause to rue.