A gloomy day with heavy overcast probably isn’t the first image conjured when people think of California. But for residents of San Francisco and other waterfront cities, it’s just a way of life.

In summer months, San Francisco residents can often drive on the Golden Gate Bridge with temperatures in the mid-50s or lower. Just a few miles north or inland, however, temperatures could be soaring with not a cloud in the sky.

The culprit for the disparity? The marine layer.

So what exactly is the marine layer and how is it formed?

The marine layer is a layer of air near the surface of a large body of water. It’s formed when warm dry air goes over a cool body of water.

When the air above the water is warmer than the water itself, a temperature inversion develops. The air right above the water surface starts to cool and becomes denser than the warm air. Because the thick, cool air is so much denser, it becomes trapped between the water or ground and the warm air.

Usually, you can tell if there’s a marine layer if there’s low hanging clouds or fog that seem to be just be stuck.

But the marine layer isn’t the clouds itself, instead it’s the air that’s keeping the fog in place.

“The cooler air below the inversion is called the marine layer and is cooled to the point at clouds form,” according to the National Weather Service.

California in particular is susceptible to marine layer, because the Pacific Ocean water is so cold as it comes down from the Gulf of Alaska. As the temperatures heat up in spring and summer, the ocean still stays relatively cold.

Warm air in the summer months traps the cold air above the surface of the water and boom — marine layer.

The low clouds and fog usually clear up in late morning or afternoon, but sometimes can stick around for days on end.

It’s not unique to California, marine layers can form near the Great Lakes or other large bodies of cool water, but the Golden State represents the ideal conditions for it to form.

So if you’ve ever found yourself wondering what the deal is with the May Gray/June Gloom — or fog monster if you’re a Santa Barbara resident — now you know.