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 also group municipalities into entities known as comarcas (districts) or mancomunidades (commonwealths). There are a total of 8,131 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,305,408 (2022), while several rural municipalities have fewer than ten inhabitants (Illán de Vacas, had a population of three in 2022). 84% (6817) of municipalities have less than 5,000 inhabitants. Castile and León alone accounts for 28% of municipalities but has less than 6% of the population of Spain. A European report said that one of the most important problems facing local governments in Spain is the very high number of little towns with a low number of inhabitants. The area of the municipal territory (Spanish: término municipal) usually ranges 2–40 km2, but some municipalities span across a much larger area, up to the 1,750.33 km2 of Cáceres', the largest municipality in the country. 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. History Municipalities were first created by decree on 23 May 1812 as part of the liberal reforms