Germany said on Wednesday it will close 31 of its 328 military bases and shrink installations in another 90 locations over the next five years as part of the most sweeping cuts in the history its Bundeswehr army, navy and air force.

The reforms are painful but unavoidable, Defence Minister Thomas de Maiziere told a media conference.

The Bundeswehr isn't there to have bases in as many places as possible but it's there to fulfil its mission well and as cost-effectively as possible.

Closing one base named after the Wehrmacht officer who tried to assassinate Hitler, Colonel Claus von Stauffenberg, was especially painful, said de Maiziere.

Stauffenberg and his co-conspirators were executed but he became one of Germany's few undisputed 20th century heroes.

Some local communities hit hardest by the cutbacks staged protests, notably in the northern state of Lower Saxony.

For decades these towns and villages that are going to be hit by these cutbacks were good hosts for the military, said Gerd Landsberg, director of the association of German towns and cities -- Deutsche Staedte und Gemeindebund. The authorities have to make sure these places don't turn into ghost towns.

Ulrich Kirsch, head of the Bundeswehrverband lobby group, said the towns must be compensated. A total of 10 of Germany's 16 states will be affected -- all in the west.

As part of the government's austerity drive, increasingly urgent as the euro zone debt crisis worsens, the German armed forces had already announced it will slim down to 180,000 from 250,000. It also scrapped conscription this year.

But even if I had another billion euros available, that wouldn't make sense (to keep bases open) because the number of soldiers will be reduced and it doesn't make sense to keep all these bases open, de Maiziere said.

At the end of the Cold War there were 495,000 soldiers in the Bundeswehr and 170,000 civilian personnel, and 175,000 soldiers in East Germany's Nationale Volksarmee (NVA).

Just last week it emerged that Germany would also slash defence orders for Eurofighter jets, Puma tanks and Tiger combat helicopters.

De Maiziere said that decisions to close or maintain a military base were made almost entirely on merit and that only in a limited number of cases would bases be kept open due to local economic conditions.

(Editing by Louise Ireland)