From: Washington D.C.
After playing around with submarines for the last day I've come to the conclusion that it is almost impossible for a submarine to attack a modern flotilla of naval ships with torpedo's and escape alive when variable depth sonars, ASW helicopters and ASROCk like weapons are involved.
Only if I fire torpedo's at extreme range and try to keep them within the thermocline layer at slow speed I may get lucky enough to hit a target if the target only has a hull sonar, but whenever there is a variable depth sonar involved I almost always commit suicide by attacking.
A nuke boat may also get lucky and outrun pursuit if only 1 ASW helo is involved but a diesel boat is 100% toast once detected.
The whole point of VDS, ASW Helos and ASROC-like weapons is to make things difficult.
I think the real trick with submarines is to recognize how vulnerable they are once detected, and also to understand what they're actually trying to accomplish on their mission.
Submarines, in general, probably don't want to get too close to warships. They're not tanks. They can't shoot their way into a given formation of warships. If they do, eventually they will be detected, attacked and killed. Surface ships have firepower, speed and endurance on their side where submarines might not necessarily. Helos extend the reach of their torpedoes. ASROCs form the next inner band of defenses. Inside of that are over the side torpedoes, RBUs and depth charges. If you have to attack one, you would probably be more survivable using long range ASCMs or max-range torpedo shots than trying to get close.
If they're attacking a surface ship it'd probably be smarter to focus on whatever it is the surface combatant is protecting, which generally isn't as heavily armed from an ASW perspective as a surface combatant. That might mean oilers, tankers, merchant vessels, aircraft carriers, amphibious ships, and other vessels which have a larger scale impact on the war effort. The name of the game is to use your sneaky stealth to avoid the combatants entirely, then blast the high value targets.
Even then, after you've shot, you've probably been detected. If you've hit anything, you've created a "flaming datum" to be searched. Even if you haven't, the sound of your weapons firing was enough to reveal your presence and say something about your location. At this point, trying to press the attack is foolhardy. Just run and hide. You still might not survive, but if you have any chance at all, that's your best chance.
Is it really this bad IRL?
Nobody can tell you that.