A ship is spotted when another enemy ship or aircraft gets close enough to detect it, and if necessary for the type of detection, has line of sight (LoS).
Detection range
The most important value is a ship's surface detection range. This is the range at which a ship will be detected by an enemy ship. A Line of Sight (LoS) is required between the spotting ship and the ship being spotted. A ship will not be spotted if there are no enemy ships within this range.
Air Detection: The detection range from the air is the same distance as the surface detection range. When a plane enters your detection range, you will be spotted by the enemy.
Launching torpedoes will not increase a ship's detectability range. Sailing slowly or stopping completely will not reduce a ship's detectability.
Firing main guns
Firing main guns will increase surface detectability ("bloom") to the current maximum range of the main guns. The detection range will go down again after 20 - 25 seconds depending on your ship.
Supplies, equipment, elite upgrades, and camouflage
A ship's detectability range can be decreased by using certain supplies, equipment, elite upgrades, and camouflage. The bonuses from each of them can also stack together, so an Akatsuki (with base surface detectability range of 6,24 km) fully decked for concealment can have a surface detectability range of only 5.37 km.
Ship Skills
Smoke
Allows you to create a smoke screen. All ships that are inside the smoke screen are invisible. The ships can use their main guns without getting detected.
Sonar
Sonar allows you to spot enemy ships that are inside a smoke screen.
Torpedoes
Ships can spot torpedoes from a fixed range based on the torpedo model. The detectability range of torpedoes by aircraft is half of this fixed detection value.
The Hydroacoustic Search (while active, detects all enemy ships and torpedoes within the specified radius, regardless of obstacles - such as smoke screens or islands) consumable temporarily increases the range at which a ship can detect torpedoes to a fixed distance. Once a torpedo has been spotted, it will remain spotted for the duration of its run.
Situational Awareness
When your ship gets spotted, you will see an icon and a "detected" message. If you are spotted by sonar, the icon will also include a sonar symbol.