When a telescope takes a picture of deep space, it doesn't take it in colour. Modern telescopes are equipped with digital cameras that employ CCD (charge-coupled device) sensors to take images consisting of greyscale pixels -- which leads many to believe that the coloured images we see from telescopes such as the Hubble aren't actually real.
This, however, isn't actually the case -- and nor is it the case that astronomers colour telescope imagery purely for aesthetic value. There are actually some very good reasons for exaggerating colour or even colouring cosmic objects with hues that would be invisible to the naked eye -- and, of course, some images are coloured with their actual colours.
So how is it accomplished -- and why?
It's true that the images captured are laid down in black and white -- but that doesn't mean that the telescope has no way of knowing how it is actually coloured. Hubble, in fact, has a number of different filters, each of which allow light on a specific wavelength or number of wavelengths. A narrow-band filter, for example, will only let through a very small portion of the spectrum, while a broad-band filter will let through a large portion -- for example, all the red and green areas of the spectrum.
This means that the telescope can take a number of pictures of the same object using a variety of filters. One image might show only light on the blue area of the spectrum, while another shows yellow, and so on. These resultant images can be combined for a full-colour composite.
The reasons for this are not purely aesthetic. A narrow-band filter, for instance, could isolate a small wavelength that is specifically isolated to a particular atomic transition, allowing the researchers to study that phenomenon in detail. Others allow astronomical researchers to view chemical dispersion or other details that would be blurred in a black-and-white image, enhance detail, or show what would usually be invisible to the naked human eye -- for example, details on the infrared spectrum.
Galaxies are usually photographed in broad-band. These allow more light to get through, and create the closest approximation to what a human might see, were he or she cruising by in a spaceship. Nebulae, on the other hand, are usually photographed in the narrow-band, which produces very sharply defined details -- and more exaggerated colour than we'd expect to see with out own eyes. This is because the telescope camera will take long exposures to pick out colours that are actually too faint for the human eye to see.
While it is true that this does result in some glorious images, there's a practical purpose: a reddish tint in a nebula might indicate the presence of sulphur, while blue might signal oxygen and green might signal hydrogen. However, without colour enhancement, all three gases correspond to different shades of red -- which makes a nebula's composition more difficult to ascertain.
Finally, some images are taken purely in spectra invisible to the naked human eye altogether: infrared and ultraviolet. These allow researchers not only to see through dense obstructions -- such as dark nebulae -- but also analyse various behaviours, such as heat signatures. However, because these spectra are invisible, the researchers assign visible light colours to various wavelengths in order to view them clearly.
For example, this image of the Egg Nebula -- and a dying star -- is depicted in representative colour: blue for infrared starlight reflected by dust particles around the dying star, green for longer-wavelength reflected starlight and red for the infrared light of hydrogen molecules around the star. This detail would be much more difficult to study were it shown in its actual visible light colours.
These images are called "false colour", but -- as you have read -- that doesn't make them fake. It just means that they are coloured along different spectra than visible light.
"The Hubble Space Telescope was not really designed to make pretty pictures,"NASA image processor Zolt Levay explained in a 2008 briefing explaining the Hubble imaging process. "The pretty pictures are kind of a by-product of the data that the astronomers get out of the telescope. The telescope was designed to do leading-edge science -- arguably the best telescope ever made."