In almost every commercial aircraft, there are several microphones built into the cockpit that listen to flight crew conversation. These microphones also track any ambient noise in the cockpit, such as switches being thrown or any knocks or thuds. There may be up to four microphones in the plane's cockpit, each connected to the cockpit voice recorder (CVR).
Microphones send audio to the CVR, which digitizes and stores the signals. In the cockpit, there is also a device called the associated control unit, which provides pre-amplification for audio going to the CVR. The four microphones are place in the pilot's headset, co-pilot's headset, headset of a third crew member (if there is a third crew member) and near the center of the cockpit, to pick up audio alerts and other sounds.
Most magnetic-tape CVRs store the last 30 minutes of sound. They use a continuous loop of tape that completes a cycle every 30 minutes. As new material is recorded, the oldest material is replaced. CVRs that use solid-state storage can record two hours of audio. Similar to the magnetic-tape recorders, solid-state recorders also record over old material.