During WWI and WWII, especially in the Atlantic, the Germans had submarines known as U-Boots (which stood for Unterseeboot, literally, "underseaboat") whose task was making sure that supply ships from the United States did not make it to Britain.
In WWII especially, Britain relied heavily on arms, ammunition, and food shipped from the United States. Cargo ships that sailed individually to Britain were often torpedoed, sometimes just off the coast of the United States by German submarines operating in what was called a "wolf pack," and, unfortunately, the sheep was the ship. The wolf pack system, which stationed U-Boots in a long line, resulted in the sinking of hundreds of thousands of tons of supplies destined for Britain and thousands of lives.
The United States, Canada, and Britain devised the convoy system in order to protect cargo ships from German submarines. Under this system, cargo ships formed up in a relatively tight-knit formation, and this formation was surrounded, front-to-rear and side-to-side by small fast warships like destroyers and destroyer escorts.
The convoy then moved in a block, with the warships protecting the cargo ships, and the system, although convoys were still attacked, reduced the number of sinkings by almost half. It took many convoys to gain enough experience to be successful, but as anti-submarine tools were refined--radar and sonar--the destroyers began to be increasingly effective against the submarines.
By 1944, submarine duty was so dangerous, especially in the Atlantic, that a German submarine had almost no chance of completing its mission unharmed. Submarine crews, in fact, suffered the highest casualties in any group in the German Army, Navy, or Air Force.