You can safely claim photography was invented when people discovered that some silver compounds react to the presence of light and change their color, becoming darker, this is the working principle of photographic film and photographic paper. Digital photography is just the same, only instead of a chemical compound, there is an electronic sensor.
To record the image, in both traditional or digital photography, you do the same thing: expose a sensor, chemical or electronic, to a certain amount of light, until it is impressed. The amount of light is called exposure and it is controlled by two factors: the size of the hole where the light enters (aperture) and the time the hole stays open (exposure time or shutter speed). So basically you can get the same exposure (amount of light) with a small aperture and a long exposure time or a large aperture and a shorter exposure time, for example you get the same exposure with f/4.0 at 1/250s and f/5.6 at 1/125s (there are creative uses for various aperture values which deserves a separate article). With exposure times long enough to get the needed amount of light you can safely take photos even at night (of course, a tripod is a must).
night photography
A parameter with great influence over the exposure is the sensor sensitivity, called ISO: back in the days of film photography you used to have slow films for sunny days or fast films for cloudy days or indoors. Larger silver compound crystals are more sensitive and easy to impress, but the resulting photo has a grainier look. The sensitivity is measured by the ISO value. Again, the digital photography is the same: the sensor has a certain sensitivity, measured by the ISO value, but the benefit is that you don't need to change rolls of film, only adjust a setting in the camera. And, of course, increasing the ISO value comes at a cost, which is a bit different from film photography, in digital you get noise, a bunch of pixels in odd colors scattered over the image, they are the result of surcharge and heating.
digital camera noise
In an ideal world you would take photos at the smallest ISO value for the best image quality, but if you don't have enough natural light, no additional light or can't afford long exposure time, you don't have a choice and must increase the ISO value to get decent exposure times. It should be noted that a good (but pricey) camera can take good images at a relatively high ISO value and probably all current digital cameras apply some level of noise reduction in software for night photography.
set the ISO value
Sometime you don't get the exposure right and get your photos underexposed (black) or overexposed (white): in both cases you lose details due too little or too much available light. Opposed to film photography, in digital from an overexposed photo, with too much details white, or 'burned', you can't recover much, but if the photo was slightly underexposed you can use photo editing software and make it brighter and recover some lost details. The result will not be great and noisy, but a noisy image may be better than no details. This is why some digital photographers have a tendency to underexpose their shots.
recover and underexposed image
There are cases when you underexpose or overexpose the photo on purpose, to achieve a certain amount of light: for example when shooting a backlight subject (contre-jour), if you expose for the sky your subject will become a dark silhouette with no details, and if you expose for the subject the sky will get burned and will become white. You have to decide which type of shot you want.
exposed for sky and subject
Tip: in such cases a flash can be useful, expose the photo for the sky and use the flash unit to light the subject and make its details visible.
All this talk about exposure may sound complicated, but it really is not. You usually use a device called exposure meter, measure the available light and set the aperture/exposure time pair accordingly. Pros usually have such external devices, but your camera surely has one included, which is used by default in automatic modes or you can take into account its values when working in manual mode. Even in semi-automatic modes (P, Av, Tv), where your camera adjust automatically one parameter accordingly with the other set manually by you, you can change the exposure compensation and indicate you want something exposed more or less.
exposure compensation
Painting with light
An interesting application is playing creatively with long exposure times, with motion blur being the simplest effect: a moving object will be recorded as a trail. As a bonus, have one part of the subject fixed and another moving.
motion blur
This is widely used when shooting water, be it waterfalls, fountains or sea waves: a short exposure time will 'freeze' the image, showing the water drops, but a longer time will blur the moving parts (the water) rendering the drops as a beautiful, continuous stream (you must have the camera placed on a tripod). This is a classic way to take photos of water but I also find it interesting for fire.
fire and motion blur
You can go forward with even longer exposure times and moving subjects, like having the exposure time in the range a few tens of seconds, have the subject for about half of the time in one position and then move it in another place. The result will be a freaky and surreal: two instances of the subject. If you want a clearer image, shortly light a flash and freeze various positions.
double impression
On the same line, if the moving object is a light source it will be recorded even better in the image, so with a bit of practice you can effectively paint (or write) with the light.
painting with light