There is no special standard for the color of warships and submarines. Basically, it is the freedom of each country to paint what color they want. They can be painted in camouflage, red or green as long as they want. Modern warships can be painted in light colors. But if you notice literally every Navy ship universally gray and Submarines painted black. Ships were sometimes camouflaged in classical times.
The gray color reduces the contrast of the ships with the horizon and reduces the vertical patterns in the ship’s appearance. It is the universal color of combatant and auxiliary surface ships, in contrast to the dark gray or black color of submarines, the bright colors of ceremonial vessels and aircraft, or the white of hospital ships and some Coast Guard cutters.

There has been a wide variation in paint schemes in the past. There was all sort of color schemes from the end of the 19th century until WWII. The US fleet in the early 20 century was called ‘The Great White Fleet, so you can guess the color Great White Fleet. Dazzle camouflage was popular during WWI. It made it hard to use range-finding devices, but was made obsolete by the invention of radar.
The gray paint is a very effective means to keep a warship from being spotted in a wide variety of situations. Gray in some shade is the best color to blend in with the haze and prevent easy visual spotting and identification. If a warship is at or near the horizon, light gray can make it very difficult to spot, even on the sunniest day – which you get less of at sea than you might think. In foggy or cloudy weather, a ship can be even harder to spot. Even if a ship can be spotted at long ranges visually, a uniform gray may delay a ship from being positively identified – and in an era where many ship designs look alike, that can make a difference.
It is also interesting to note that gray is only universal for the side view. The upper decks vary quite a bit. Russian ships use a green and or red deck scheme. US ships are a darker gray known as deck gray, While the Indian Navy uses gray for side view and for deck it use dark gray Some navies use green-gray etc.
Submarine
As for submarines, submarines are not strictly “black”, they just tend to be black indefinitely, and there are even submarines in off-white, green, blue and red.
For example, the German “Dolphin” submarine purchased by Israel used to be painted in a variety of colors, including sky blue and green. Finally, in order to coordinate with the green waters of Tel Aviv and perform some special tasks, the Israelis determined the submarine as green.
Most of the submarines are painted full black. Some countries paint their submarines in two colors. The top part of the submarine is painted black and the bottom part of the submarine is painted orange. And also, some of the small submarines are painted green.

The main reason why submarines are painted dark is that dark colors reflect less light and are easier to camouflage themselves in visual observation. But don’t underestimate this point, anti-submarine does not rely only on sonar, visual observation is also one of the important channels.
Submarines with insufficient diving depth are still very likely to be discovered after avoiding surface refraction through aerial observation; even sometimes due to changes in light, submarines will be discovered by ships. Dark paint is beneficial for submarines to quickly and underwater. The dark environment blends together.

Especially for those ocean-going nuclear submarines, their missions are extremely secret. Sometimes they have to pass through dense waterways with ships, or simply take the cover of ships to avoid sonar. If you paint a glittering gold and silver shape, it will increase your chances of being discovered, maybe someday. It capsized in the ditch.
If you look closely, you will see the submarine pattern is same on fish, such as tuna, such as the blue top and white bottom because to a predator above them, the blue pattern blends with the blue ocean, but if it is a predator below them, the white pattern blends with the white sky.
In addition, modern nuclear submarines emphasize quiet performance, and usually have outer covering absorbing materials, such as the once famous “absorbing wave” and so on. The main component of these materials is rubber. The color of the special rubber is black. They cover the surface of the submarine, and of course the submarine is black.