SONAR has two main modes of operation: passive and active.
Passive SONAR is typically employed by ships and especially submarines to detect and identify enemy vessels without giving away their own position. The basic operation of passive SONAR is to have an operator listening very carefully to several acoustic hydrophones positioned on the outside of the hull of the ship. A good SONAR operator can tell by carefully listening to the sounds received what other vessels are nearby. Most modern SONAR systems make use of computers with databases of known undersea sounds to assist in the identification of sound sources in the water.
Active SONAR uses a sound emitted by the vessel, often referred to as a "ping", to gain precise information on a potential target. Like all forms of active sensors, it has the disadvantage of alerting any other vessels nearby that are listening. While passive SONAR is able to identify the general location of a potential target, active SONAR is required to gain the precise distance, vector, and bearing of that target. The use of acoustic homing torpedoes usually means that active SONAR is not required to lock weapons and fire at a target.
There are various adaptations of SONAR technology that have been built to take advantage of its ability to provide accurate mapping of the ocean floor. These include side scan SONAR which is an active SONAR that can be mounted on the bottom sides of vessels or onto towed arrays that allow for detailed mapping of the ocean floor. Side scan SONAR is accurate enough to allow it to locate sunken ships on the bottom of the sea miles from the unit.
There are also specially designed SONAR buoys that can be dropped from both ships and aircraft that can allow for remote use of active SONAR while the deploying vessel can remain mostly undetected (as the buoy's active pulses will cause echoes off everything, friend or foe) while still benefiting from the higher accuracy of an active SONAR lock. These are only useful in small numbers, as too many SONAR buoys can saturate an area with noise, effectively jamming all SONAR systems in the vicinity.
Passive SONAR can also be deployed in fixed sensor posts deployed on the seabed or fixed buoys that allow for the monitoring of traffic through an area. They do have the disadvantage of being predictable in ways that a mobile monitoring unit would not be, making it possible for enemies to find ways of bypassing or spoofing those sensors.
SONAR decoys are devices that are designed to make lots of noise in order to confuse enemy acoustic torpedoes fired by an attacker in passive mode in order to prevent those weapons from locking onto their intended target. Once deployed, however, they have the disadvantage of blocking most of the deploying unit's own passive SONAR capability and revealing their approximate position. If the decoy works, it may at least offer an opportunity to attempt to fire back.