The Bases in Norway
The Norwegian coastal cities became available to the German Navy after the daring (and costly) German victory in Norway in April-May 1940. Having U-boats there greatly helped extend their range into the North Atlantic and not to mention threaten the convoys traversing the Arctic Ocean into Russia.
Flotillas in Norway
Over 240 U-boats were stationed in Norway at one time or another, most in the 11th flotilla which had about 190 U-boats in its ranks during its career. A great number in addition were supplied there in some way.
Hammerfest and Kirkenes mostly served to support the Arctic Ocean patrols against the Murmansk convoys.
The fall of France
Just before the fall of France during the fall of 1944 a great number of U-boats were moved from their French bases to Norway and Germany. At this time the 13th flotilla in Trondheim was regrouped with some of these boats.