After doing a little research, I can now tell you (basically) everything you ever wanted to know about black boxes...
In the average commercial aircraft, you'll find the presence of multiple (usually four) microphones in the cockpit at any given time. They are located in the pilot and co-pilot's headsets, as well as in the cockpit itself. Not only do these microphones record conversations between the pilots and cabin crew, they also record any ambient noise (such as switches being thrown or sounds generated by technical issues). The microphones all connect to the cockpit voice recorder (CVR), a master unit that stores the last 30 minutes of sound. The tape operates on a loop, essentially erasing itself every half hour.
This device is known colloquially, but a little misleadingly, as the black box (it is usually quite brightly coloured in order to make it easier to find in the unlikely event of an accident). Another device also referred to as a black box, is the flight data recorder (FDR), which automatically records data regarding the plane's flight path, speed and movements in the air. Although the devices are distinct from one another, the information they record goes to the same place and is used for the same purpose, thus their shared name of black box.
In recent years, manufacturers have moved away from magnetic tape-based CVRs and FDRs and towards solid state technology boxes. These improved devices store the relevant data on memory boards, which can hold up to two hours of cockpit recording and 25 hours of flight data. The solid-state devices are also sturdier than their tape-based counterparts.
Crash survivable memory units (CMSUs), are large cylinders that back up all the relevant data and are designed to withstand extreme heat, pressure and violent impact. They are typically contained within the box itself. In the more severe accidents, the CMSU is all that survives of the black box.
The black box, then, simply records all the relevant data before an accident occurs. This serves to provide engineers with an explanation for a crash, as well as providing investigators and regulators with the same information.
So there you have it, of course, a lot of information is stored in an aircraft's black box (much more than I've detailed here), but as a general example, that's what it is and how it works. Hope that helps.