The answers by AlexD and kingledion both assume that the submarine is a modern state of the art military boat, but there is much more to it than that.
The Soviet era Alfa submarine had a Titanium hull, which is non-magnetic and much harder to detect with magnetic anomaly detectors, effectively making them useless. However, as submarines go, while very fast, it was also noisy, which is the last thing a naval submariner wants.
So, if MAD is rendered irrelevant, and since optical observation - either visible or infra-red - by aircraft or satellite is dependent upon the submarine remaining above the Secchi depth, which at sea is between 1 and 50 metres, most typically around 20m in the deep ocean, but less in more coastal and disturbed areas, any submarine capable of submerging below 50m or whatever the local Secchi depth is can go unseen.
Similarly, water attenuates radar severely at the frequencies typically used for surface search and tracking, making these radar sets useless for underwater search. Low frequency radar can penetrate water effectively, but even aboard a ship the antennas required are impractically large.
This leaves only sonar. Water transmits sound extremely well - but all sounds, not just those of submarines. There is a constant background noise into which a submarine may vanish if it is quiet enough. Modern submarines detect each other using waterfall displays, where the width of the screen represents the unwrapped 360° space around the sub, and the vertical axis represents time, with the current time at the top. With no contacts, the waterfall display shows random dots, but a noise-emitting contact results in a line, vertical if it is at a constant bearing, otherwise it is slanted from the vertical. The sonar operator can select a contact and use a frequency spectrum analyser to split the sounds emitted by a target into discrete frequencies over time, and finally, the sonar operator can listen to the contact.
Man-made objects such as ships and submarines have distinctive sounds that separate them from geological and biological sounds. Ships and subs usually have propellers, and sonar can - when close enough - detect the individual blades as the screw turns as a kind of beat. The faster the screw is turning, the louder and easier it is to detect, as the blades cause cavitation once the blades are travelling through the water fast enough. A vessel can be tracked by guessing its type from its sound, calculating a blade-rate, guessing (or hearing) the number of blades based upon the probably type of contact - if the propeller is worn or damaged, determining the number of blades can be achieved from observation since each blade takes on a distinct sound of its own - and then guessing (or knowing from prior experience) the speed-per-RPM and calculating the probable speed. From that, and knowing the movement of one's own submarine, a reasonably exact course can be determined for the contact over a period of time, perhaps 15 minutes, since the bearing at each moment will be known, and the probable speed can be used to fit the course with time markers to the observed bearing to the target at those times. By moving the proposed course around until its time markers match with the bearing at those times, the actual course can be determined. Choosing an inappropriate speed can be detected using this method, since it will usually result in the appearance of a curved course, while most ships travel in straight lines for the most part.
So, in a break-away contest, we have the villain's submarine and we can assume the pursuer's. The villain would want as quiet a sub as he could manage - let's hope he hasn't gone with a noisy soviet-era nuclear clunker unless he's spent a fortune refitting it. Nuclear subs are actually noisier - they sound like a kettle on the boil - whereas diesel-electrics are much quieter except when snorting to recharge their batteries. Some modern subs only emit sound below ambient when running silent and at low speed, these would include US missile submarines and some new diesel-electric subs. However, at close range, even emitting below ambient isn't necessarily going to help against a pursuer with experienced sonar men and state-of-the-art sonar transducers - they can see the shadow the fleeing sub makes in the background noise, as well as hear the distinctive mechanical sounds.
However, that isn't all there is to it. A fleeing sub can use decoys to produce the sounds that the pursuer is expecting to hear in a place other than that where the pursued is, or to simply fill the water with bubbles that mask the sounds beyond it. The water temperature typically decreases somewhat as depth increases, but there are also strata of temperatures within the seas, with thinner strata across which temperature changes rapidly, known as thermoclines, which - because they refract sound - can be used to hide from an enemy. Some locations have multiple thermoclines, or there may be only one, or none at all in shallower areas. Consider the confusion caused upon the pursued dropping a moving decoy above a thermocline, then ducking beneath that thermocline and changing direction. Some sonar crews may fall for the deception, and continue to report the incorrect course that the decoy is taking rather than reporting that the target has changed depth and released a decoy.
Changing depth has its own acoustic signature - a creak or groan as the pressure upon the hull changes, resulting in it expanding or contracting. Launching a decoy or torpedo may be heard, since these devices are loaded into dry tubes that are then flooded - with a sound like that of a toilet flushing - the tube doors opening, with associated mechanical sounds, and then a shot of high-pressure air to eject the device, again with a distinctive sound, much louder in the case of torpedoes than decoys. Some torpedo-tube launched mobile decoys are "swum" out, being launched without the shot of high-pressure air to keep things quiet.
In detection and evasion exercises between submarines, a sonar telephone is typically used to announce the administrative launch of a torpedo, but it is also known for a torpedo tube to be fired empty, particularly where the participants in the exercise are not all that friendly, to wake up a negligent ally, or to flush out a lurking enemy. The distinctive sounds of a torpedo tube being flooded, opened and fired are much like the sounds of a pistol being cocked are to a land-dweller, or even worse, since they represent not just the weapon being armed but actually fired, and it takes an experienced sonarman to be able to tell the difference between a loaded tube and an empty tube being flooded and fired. Also, since the firing of a tube releases a mass of bubbles, the torpedo engines won't be heard for a second or two, and any decently-trained sonar man will report a torpedo launch on hearing the first sounds without waiting to hear the torpedo, since seconds can make the difference between life and death when attempting to evade a torpedo.
Evading a torpedo is possible by going to maximum speed, releasing a decoy (often static) and then changing direction, hoping that the torpedo sonar will acquire the decoy's bubble cloud rather than the sub while the sub heads in another direction. A counter-attack shot down the line of bearing to an enemy torpedo may be useful to get the attacker to cut the guidance wires to their own torpedo in order to maneuver - an unguided torpedo has to rely upon its own limited brains rather than those of a human crew while its guidance wire is stall attached, and a miss is more likely when unguided, since a crew can both listen through and manually control the torpedo while on the wire.
So, a torpedo launch, whether real or dry, is cause for a submarine to go to full, noisy, power, and it takes experience to know if the launch might be a bluff which can be ignored, or is a potentially deadly attack which must be evaded. An evading submarine can be made to reveal its presence by going to full power, but on the other hand, an evading sub may also launch a live torpedo or dry-fire a tube in order to get their pursuer to go to full speed, since at higher speeds, flow noise degrades sonar performance, giving the pursued a chance to vanish into the background noise while the pursuer is running and can't hear.
It is of interest that drug cartels are now building single and multiple-use submersible craft to smuggle drugs. These narco-subs are increasing in sophistication, but have also led to laws - in the US at least - outlawing the use of an unflagged submarine in international waters, so the OP's villain had better have a pretty good sub, or at least have a registered sub and a good excuse to be using it in the event of capture.
If we're talking about a James-Bond style villain with heaps of ill-gotten gains and global contacts in the right places, his submarine could well be an all-up torpedo-armed sub of a quality equivalent to the best in the world, something that even the US authorities would have difficulty tracking and capturing, or it may be a more improvised affair, a-la the Columbian narco-subs.
So, as I've shown, the "range" of sonar depends upon all sorts of things, and can't really be expressed as a hard number. An advanced submarine evading a poor pursuer may not be detectable at a few hundred metres range, or the other way around, may be detectable a hundred kilometres away. Given technical parity, a realistic detection range might be ten to thirty kilometres, and even that depends upon the skills of the respective crews. Also consider that detection and capture are different things - when we're talking about armed subs, a single torpedo is a game-changer - if our villain launched just one real torpedo, with a decent motor, range and sonar seeker, it would scare the opposition into handling the situation far more conservatively regardless of wether the torpedo did any actual damage, and potentially allow the villain to escape.
On the other side, many first-world nations have emplaced sonar networks. The G-I-UK SOSUS net that runs from Greenland to Iceland to the UK was emplaced to detect soviet submarines, and while effective, was never infallible. Local sea conditions can reduce sonar performance, the sub captain's patience and knowledge could lead him to creeping past the sensor net so slowly that the sub just isn't heard, or the sub captain could use a convenient merchantman as a hat, travelling beneath it in order that the sub's signature be lost amongst the merchantman's noisier signature.