At its most basic, sonar is a contraction of sound navigation and ranging, a technique in which a sound pulse is generated by an acoustic transducer, and an acoustic receiver listens for the echo of the pulse from some reflector. The reflector need not be a hard object, but can, for example, be the transition between water and gas.
In practice, the technique includes passive sonar or hydrophones, which only listen for sounds generated by objects of interest, such as hulls flowing through water or propellers turning in it. For a wide range of active and passive methods, see acoustic MASINT.
SONAR is generally interpreted to be a technique used in water, although passive acoustic receivers are used for such things as locating artillery by the sound of its firing. A related area uses microbarographs to detect the changes in air pressure caused by the shock waves of explosions.