The in-depth answer to this question would take far more space than allowed here, but can be summarized by looking at the parts of the eye itself, and how the information is sent to the brain.
The eye works somewhat like a camera. Light enters through the cornea and the lens, which help focus the light entering based on how far away the light rays are coming from. The pupil and iris adjust the amount of light coming in, so that the brightness is the correct amount, not too bright or too dim. At the back of the eyeball is the retina, the actual nerve endings that sense the light entering the eye and transmit the information via the optic nerve to the brain. The retina is a group of light sensitive cells that send information based on the light rays entering the eye. The information is then sent via the optic nerve through part of the thalamus to the cerebral cortex of the brain. The information is interpreted in the brain; the information which the nerve fibers transmit is formed into an image in the brain itself. This is a very complicated process; the second link below will take you much more in depth than the limited amount of information I can present here possibly could!