The municipality called "Hammerfest by og landdistrikt" was established on 1 January 1838 (see formannskapsdistrikt). It included the town of Hammerfest and the vast rural district surrounding it. The law required that all towns should be separated from their rural districts, but because of low population, and very few voters, this was impossible to carry out for Hammerfest in 1838. (This was also the case in the nearby towns of Vadsø and Vardø.) In 1839, the northern district (population: 498) was separated to become the new municipality of Maasø. This left "Hammerfest by og landdistrikt" with 2,024 residents. On 1 January 1852, the rural district outside of the town (population: 1,256) was separated from the town of Hammerfest to form the new municipality of Hammerfest landdistrikt. This left the town with 1,125 residents. (The rural district was later divided into two municipalities with Sørøysund in the north and Kvalsund in the south.)