Frost and fog are siblings. They are born of the same parents - a windless atmosphere married to a cloudless sky. The youngsters thrive and co-exist in the common environment from which they spring, and like any siblings they are often seen together; both, for the most part, are creatures of the night.
In the strictest sense, the term "frost" refers simply to the occurrence of a temperature of zero degrees Celsius or below, regardless of whether or not there are any visible signs of its existence. This is most likely to happen on calm, still, starry, nights. The clear skies allow the ground to lose heat rapidly; it surrenders the energy it has absorbed from the sun during the day out to space in the form of long-wave radiation.
If, on the other hand, there is a layer of cloud a thousand feet or so above the ground, it acts like a blanket on the landscape after dark and prevents the temperature from falling very much below the daytime values.
In addition, an absence of wind means that the air near the surface of the earth is stagnant, and remains in prolonged contact with the cold surface, becoming continually colder without being diluted by any warmer air mixed in from the layers above. And so the temperature near the ground may well drop down to zero.
With their usual pedantry, meteorologists are careful to distinguish between "air frost" and "ground frost" since there is often a marked change in temperature with height in the first few feet above the ground.
Fog occurs in very similar conditions. Like frost, it depends for its existence on the fact that on clear nights any solar heat absorbed by our planet during the day is re-radiated into space. The air takes its temperature from the surface with which it is in contact, so once again it is the gradual cooling of the ground on these calm, clear nights that provides the initial stimulus for fog.
Air always contains a little moisture in the form of water vapour. Moreover, the amount of water vapour that it can comfortably accommodate is crucially dependent on its temperature: the warmer the air, the more moisture it can hold.
If, therefore, the temperature of a volume of air falls sufficiently, sooner or later it will reach a point where it can no longer hold all its moisture - called the "dew point" - and the excess condenses into tiny drops of water, there to remain suspended and obscure the visibility. It is the phenomenon we know as fog.