The origins of the town go back to the Kőszegis, the oligarchs of the region, who are assumed to have laid the foundations for a town to strengthen their position.
When planning the castle and the surrounding urban area, the layout of towns planned and built by an alliance with Ottokar II of Bohemia were certainly taken into account. The chief feature of that design was the rectangular layout with the castle in one corner that also had a similarly regular arrangement. In the mid-13th century, Austria was in the forefront in establishing castle towns with a regular layout (e.g. Marchegg, Loeben, Bruck an der Mur) but Bohemia followed this practice: two such towns, Kadan and Domazlice, have been classified as castle towns (burgstadt).
Kőszeg, the first Hungarian example of a castle town, was built along regular geometrical patterns: the main streets and gates were positioned along a straight axis, there was a central square with the castle on one corner. When Charles I occupied the town, he put an end to the abuse of authority of the Kőszegis, and in 1328 he made it a free royal town. Kőszeg soon became an important market town, a fact also illustrated by the town’s market-centred street structure in the 14th century.
King Charles I granted tax exemption in 1336 to the town for ten years but in exchange he demanded that walls be built not only around the castle but around the whole town. Later, when the royal estate, the landlord’s castle and the surrounding urban areas were united, a unified defence system was created. When in war, the prevalent captain of the castle was in charge of defence and citizens had to obey his orders at all times.