How does a camera work?

Cameras are everywhere! There are probably 2 or even 3 cameras in your pocket right now. But how do they work? How can they take some of the most amazing pictures ever?