That's a very broad question, and the effectiveness of German subs and Allied ASW varied wildly during different parts of the war. By the end of WW2 though approximately 75% of the Ubootwaffe's sailors had been killed. That should tell how you effective Allied countermeasures were by war's end.
If you look at a graph of shipping lost to u-boats, you see a bell shaped curve, with shipping losses of around 200,000 tons per month early in the war, peaking at around 800,000 tons per month in mid 1942, and dropping blow 100,000 tons per month by late 1943.
A couple of factors contributed to the rise of shipping loss. One of the largest was the destruction of Germany's surface fleet primarily by the British navy. With the surface fleet gone, and the initial success of the u-boats as anti-merchant weapons, German naval priorities became almost exclusively focused on submarine warfare.
Then a few factors led to their decline:
The Allies changed their tactics, bringing merchant ships across in convoys of increasing size. This allowed destroyers and anti-submarine aircraft to concentrate on their defense.
Anti-submarine weaponry improved
The German Enigma code was broken, allowing naval planners advanced knowledge of submarine dispositions
The centimetric radar system was deployed, which was able to spot the conning towers of partially submerged u-boats as well as occasionally being able to spot periscopes of submerged subs
All of the above led to increasing u-boat losses. A total of 68 u-boats were lost between 1939 and 1942 and 86 were sunk or captured in 1942 itself. This skyrocketed to 241 lost in 1943 and 234 in 1944. When a u-boat was destroyed the crew generally either died or were captured. As the war progressed, there were simply fewer experienced u-boat captains and crews, and their replacements couldn't be trained fast enough to offset the losses.
To answer your question, the u-boats were very effective, but so was the Allied response to them.