Before the start of World War II, Nazi Germany had to adhere to the Anglo-German Naval Agreement, which stated that the Kriegsmarine was allowed to have a strength of 35% of the Royal Navy at max, except for submarines. In January 1939, Grand Admiral Erich Raeder got the Z Plan approved by Adolf Nazi. When the war started, Germany had 57 subs ready, but only one third of could be used at the same time. The Rudeltaktik (wolfpack tactics) was used since October 1939.
The British and French immediately began a blockade of Germany, although this had little immediate effect on German industry.
The pocket battleship Admiral Graf Spee went on commerce raiding from September to December 1939 in the South Atlantic, forcing the Allies to hunt her with eight groups including aircraft carriers, until it had to scuttle itself after a fight with British Ships. After that, Germany only had armed merchantmen left outside the North Atlantic.
On September 14th, the U 39 was lost after a failed attack (there were technical Problems with the Torpedoes) on the British aircraft carrier Ark Royal. This was the first time British Sonar was successfully used.
In October 1939, Günther Prien with U 47 went into the British navy base of Scapa Flow and sunk the battleship Royal Oak there. In September 1939, British aircraft carrier Courageous was sunk by U 29. After that, even Sceptics were convinced of the strength of the submarines, and Production accordingly changed.
With the new invention of the magnetic Mines, the Germans sunk many British Ships, until Charles F. Goodeve developed degaussing. He also had the Idea to use wooden Ships for Minesweeping.
During the occupation of Norway, the Kriegsmarine lost the heavy cruiser Blücher (at Oslo), the light cruiser Königsberg, und during the fights for Narvik ten destroyers. The RN lost the aircraft carrier HMS Glorious, the cruisers Curlew and Effingham, and nine destroyers.
Now the Brits occupied Iceland and the Faroe Islands to prevent the Germans from occupying them.
When Italy joined the war on June 8th in 1940, submarines of the Italian Royal Navy (Regia Marina) joined the German ones. Together with the defeat of France, the naval situation in the Mediterranean has changed much in favor of the Axis Powers.
On June 27th, the Brits attacked the French Fleet at Oran and destroyed one (of four) battleships, damaged another one, plus four (of six) destroyers. Over 1,000 Frenchmen were killed because of this, which Nazi propaganda used against Britain. At the same day, they captured French ships in the harbors of the British Empire, thus giving Free France a new navy of two old battleships, two destroyers and five submarines, plus smaller vessels. This is why Vichy France broke off diplomatic relations with them. On July 2nd, further British attacks on Oran and Dakar happened.
During the whole war, the Germans (just as in the First World War) used Hilfskreuzer (Auxiliary cruisers), which used the Flags of neutral or Allied Nations, and - like modern freebooters - sank Allied Ships, or captured them and sent them back to Germany with Prize Crews. Among these captured Ships also were Whalers, (valuable) oil tankers, and refrigerator ships for food, which the Germans called "swimming Delicatessen shops".
The Imperial Japanese Navy was allowed to become 70% as strong as the Royal Navy / US Navy, but this didn't help Germany or Italy much.