Flag of the Kriegsmarine.
Prior to the war the admiral of the U-boats, Karl Doenitz, had advocated a system known as the wolfpack, in which teams of U-boats would gang up on convoys and simply overwhelm the defending warships accompanying them. He also developed a theory of destroying an enemy fleet, not by attacking their ships directly, but by cutting off their supplies so they could not be used — an economic war. In order to be effective he calculated that he would need 300 of the latest Atlantic Boats (the Type VII), which would create enough havoc among British shipping that she would be knocked out of the war.
However the U-boat was still looked upon by much of the naval world as a poor-man's weapon, and deliberately hunting merchant ships to be used only by cowards. This was true in the Kriegsmarine as well, and the Grand Admiral, Erich Raeder, successfully lobbied for monies to be spent on large capital ships instead. These were of even more dubious use considering the huge British fleet facing them, and even Raeder himself suggested they would be wiped out very quickly in the event of war.
Thus the U-boat fleet started the war consisting mainly of the short range Type II that was useful primarily for mine laying and operations in and around the British coastal areas. They had neither the range nor the supplies to operate far from land, and as a result the RAF was able to counter the U-boats to some degree with standing patrols by Coastal Command aircraft.
Meanwhile Royal Navy destroyers were being equipped with increasingly powerful sonar systems (known to the RN as ASDIC) and were able to block the exits into the North Sea and the Channel with some success. ASDIC was unable to find U-boats on the surface where they spent the vast majority of their time, but with aircraft cover forcing them underwater, running to the Atlantic could be a somewhat dangerous operation.
However with the fall of France the Kriegsmarine gained direct access to the Atlantic Ocean. Huge fortified concrete ports for the U-boats were built, which were able to resist any successful bombing throughout the course of the war. Most of the U-boat fleet was moved to these bases where they also had excellent air cover, making it much harder for both the RAF and RN to do anything about it.
However the German effort also had problems of its own. Their torpedoes continued to fail with an alarming rate, and the director in charge of their development continued to claim it was the crews' fault. It wasn't until early 1942 that the problems were completely addressed.
Another issue was finding the convoys in a very large ocean. The Germans had nowhere near the number of patrol boats or tracking stations needed to make accurate fixes from shore. Instead they had a small handful of very long-range aircraft (namely the Fw 200 Condor) used as spotters. To this they added code-breaking efforts, which eventually succeeded in breaking the British Merchant Marine codebook, allowing them to time the convoys as they left North America from Halifax, Nova Scotia.
The primary source of tracking was the U-boats themselves. They were strung out in lines across the North Atlantic waiting for a passing convoy. When spotting one, they would radio the position back to Kriegsmarine headquarters, where an effort would be made to vector other U-boats onto the attack. As the numbers of U-boats and the proficiency of the headquarters grew, they were eventually able to consistently form the wolfpacks that Doenitz wanted.