It's all very simple really. In the CMOS (complementary metal-oxide semiconductor) sensor that sits in the majority of digital cameras, the sensor is covered with tiny light sensitive cells, each of which can measure the amount of light that falls on it.
The cells act like the old photosensitive film, reacting to the light which falls on them and then reporting to the camera's microprocessor brain. The camera doesn't just look at an individual pixel on the sensor; it also looks at the pixels around it to come up with an informed guess of what the true colour of that pixel is. As cameras have evolved so have the number of pixels on the surface of the sensor. To find out more about how cameras create an accurate image watch James May above.
For more videos subscribe to the Head Squeeze channel on YouTube.