Municipalities of Spain

The municipality (, , , , , ) is the basic local administrative division in Spain together with the province.
Organisation.
Each municipality forms part of a province which in turn forms part or the whole of an autonomous community (17 in total plus Ceuta and Melilla): some autonomous communities have additional second level subdivisions, such as "comarcas" (districts) or "mancomunidades" (commonwealths). There are a total of 8,118 municipalities in Spain, including the autonomous cities of Ceuta and Melilla. In the Principality of Asturias, municipalities are officially named "concejos" (councils).
The average population of a municipality is about 5,300, but this figure masks a huge range: the most populous Spanish municipality is the city of Madrid, with a population of 3,141,991 , while several rural municipalities have fewer than ten inhabitants (Villarroya, La Rioja, had a population of eight in 2015). The area of the municipal territory (Spanish: "término municipal") usually ranges 2–40 km2, but municipalities such as Tremp (Lleida) cover more than 300 km2.
The organisation of the municipalities is governed by a 2 April 1985 law, completed by the 18 April 1986 royal decree. The Statutes of Autonomy of the various autonomous communities also contain provisions concerning the relations between the municipalities and the autonomous governments. In general, municipalities enjoy a large degree of autonomy in their local affairs: many of the functions of the "comarcas" and provinces are municipal powers pooled together.
The governing body in most municipalities is called "ayuntamiento" (municipal council or corporation), a term often also used to refer to the municipal headquarters (city/town hall). The "ayuntamiento" is composed of the mayor (Spanish: "alcalde"), the deputy mayors (Spanish: "tenientes de alcalde") and the deliberative assembly ("pleno") of councillors ("concejales"). Another form of local government used in small municipalities is the "concejo abierto" (open council), in which the deliberative assembly is formed by all the electors in the municipality.