Light passing through a medium such as air or water can be absorbed and scattered by the molecules in the medium or refracted by changes in air density. Earth's atmosphere contains air, water and dust molecules that cause light rays from the sun to change direction as they pass through slightly different densities of air - this is known as refraction. The amount of refraction of light is dependent on the refractive index (a measure of how much a substance bends light, dependent on its density and the type of molecules) and the incident angle at which the light enters the substance. Denser substances such as water will bend the light more than a less dense substance like air, and light entering a substance at an angle will refract more than entering perpendicular to the substance's surface. Air itself can have different indices- air that is warm will be less dense and so will refract light less.
Looking up in the direction of the zenith, an observer will look through one air mass- ie the minimum amount of air that light from the sun will travel through to the surface. Light at an angle z from the zenith will pass through more air, so travels through an equivalently greater air mass at a greater incidence angle z. Roughly, the air mass varies with secant z,
as cos(z)=1 airmass / n airmasses in a first-order case,
although for large angles (for more than about 60 degrees) away from the zenith, this is less accurate due to the spherical nature of the atmosphere. At the horizon, light will travel through a maximum of about 38 air masses to reach an observer at sea level.
However if the observer is above sea level, for example on a mountain or in a plane, the air mass can be greater than 38, due to the line-of-sight passing through more air before reaching the observer's horizon.
This change in air mass depending on where an observer looks in the sky changes the amount and type of light reaching the observer's position. Rayleigh (1871) found that the probability of a single photon (or packet of light energy) being scattered by an air molecule was inversely proportional to its wavelength to the fourth power. Blue light with a wavelength of about 450nm has more chance of being scattered than red light at 660nm. Light (especially the blue end of the spectrum) travelling through a greater air mass will be scattered more as there is more chance of encountering particles over this larger volume in the line-of-sight. The consequences of this are that the sun (as a single source) appears dimmer and redder near the horizon than from the zenith, as more light, especially bluer light, is scattered out of the line-of-sight to the observer. At zenith the sun's light is not scattered as much and so only a little blue light is lost- the sun appears white or slightly yellow. Conversely skylight (light from the sun scattered onto air and water molecules and so arriving at the observer from a direction other than the sun) looks bluer as it is mostly the blue light that is scattered in all directions that reaches the observer.
Objects with a measurable angular size such as the moon and planets do not appear to twinkle- this is due to the fact that light from the object is reaching the observer from all points on the object's disk. If one light ray is refracted out of line-of-sight, it does not make a noticeable difference to the observer, and light from the whole disk can not be deflected at the same time. There is also a chance that light from another point on the disk would be refracted into the line-of-sight so the intensity of light would not change.
An observer, therefore, can only be sure that what he is looking at is a true representation of an object if he is looking straight up to the zenith. Any view towards the horizon will be subject to increasing refractive and scattering effects, that can cause disparity in an object's position, changes in the colour of the incoming light and minute changes in the quality of light causing twinkling.
Sources:
David K Lynch and William Livingston; Color and Light in Nature, Cambridge University Press, 2nd Ed. 2001
Fraknoi, Morrison, Wolff; Voyages through the Universe, Saunders College Publishing, 2nd Ed. 2000
Scientific American: Ask The Experts
Astronomy Picture of the Day: Why Stars Twinkle