These can be run from submarines, towed arrays that operate from the surface, and units on naval surface vessels like the destroyer.
Active sonar is by far the most complicated.
Basically, a sound is sent out from special equipment aboard a ship, and bounces off objects in the general area, then returns to the sender. This can be used to determine remarkably detailed images of ships, or surrounding terrain, which explains why sonar is a primary tool used by ocean floor researchers. The flaw with active sonar for ships like Navy submarines is that other subs can determine your position from your ping , or the sound active sonar transmits. Hence, we have passive sonar, which is primarily used for detecting other sonar pings. This can be used to track a ship that might be trying to track you.