Bats do it, whales do it, even subs at sea do it.
They each find out about their surroundings with reflected sound waves. Dolphins are so good at it that they can tell the difference between balls two inches in diameter and others only an eighth inch larger. The common name for the process is SONAR, which is an acronym for Sound Navigation and Ranging.
How it Beagan
The process of underwater sonic detection began in World War I and continued through World War II to combat the German submarines trying to destroy the maritime trade which kept Great Britain alive. The British developed a system know as ASDIC, which was put on destroyers to help find submarines. As this system was improved, it was also deployed on both sides.
Passive and Active
Sonar has two modes, passive and active. In the passive mode, you listen to hear what is going on. Different kinds of ships make different kinds of sounds and so it is possible to tell what kind of ship is going by and in what direction it is just by listening. In the active mode, the sonar sends out a pulse of sound energy known as a ping. This is quite short in duration, and the ping travels out at the speed of sound in water. When active sonar is used by surface ships or submarines, it is typically activated very briefly at intermittent periods to minimise the risk of detection.
How it Works
When it hits something in the water, some of the energy is reflected back to the receiver. By knowing how long it takes to get from the sub to the ship and back to the sub, and knowing the speed of sound in water, you can tell how far the ship is from the sub, and which direction.
Unfortunately, the ship can also hear the ping and tell the direction to the submarine, so active sonar can be dangerous to use in warfare. Much of submarine and antisubmarine warfare has to do with sonic detection and the avoidance of being detected. There are thermal layers in the ocean which have different density. Sound bounces off these layers, and so submarines often travel under the layer making it more difficult to detect them from the surface.
The sonar used by bats, dolphins and whales is more sophisticated than anything we have, and much of sonar research is aimed toward better visualization of whatever is reflecting the sound waves so that someday we can do it as well as it is done in nature.