Sonar works on the principle of reflection of waves i,e., echo.

In this case, a strong ultrasonic wave signal from transmitter, placed inside a ship is sent towards the bottom of the sea. The signal is reflected back from the bottom of the sea and is received by the receiver in the ship, Knowing the time after which the reflected ultrasonic waves come back to the ship and also the speed of signal in water, we can calculate the depth of the sea using the following formula.
d = t x t/2
Where v = speed of signal in water
t = time after which the reflected
signal reach back to the ship.