Rather than [u]overdubbing[/u] where one layer is added at a time, most modern recordings are [u]multi-tracked[/u]. With multi-track recording, each instrument and vocal is recorded separately.
Often, several tracks are recorded at once and other tracks (such as vocals) are recorded later. Or, sometimes a backing-track is recorded first (such as the drums) and then the other instruments are recorded one at a time. Or, you can record several tracks at once and then if one musician makes a mistake, that one track can be re-recorded later. Or, you can record all of the instruments at once and record vocals later… etc.
A ‘click-track’ is often used (monitored in headphones) so that each take has exactly the same tempo. Then for example, you can use the guitar from take-2 and everything else from take-1, or you can use a few measures of guitar from take-2, etc.
With multi-tracking you can adjust the volume of each track separately and add effects separately (such as adding reverb to the vocals, or using pitch correction on the vocals, etc.) Typically “volume automation” is used to adjust the volume of different parts of each track differently (like Audacity’s Envelope control.
The MIDI applications mentioned by Steve are also DAW (Digital Audio Workstation) applications capable of multi-track audio recording. Multi-track audio recording is often combined with MIDI.
A few more comments on MIDI…
Since with MIDI you are not recording audio, the “character” of the synthesized instruments will be different from the sounds built-into your keyboard. And, since you are only capturing the notes & timing, you can take a MIDI recording and change from a piano sound to a saxophone sound, etc. You can also edit the timing or pitch one note at a time, or create MIDI completely in software without “playing” it on a musical keyboard at all.
It’s very common for home recording musicians to use MIDI drums (or for any instruments they don’t own or don’t know how to play). The one thing you can’t do with MIDI is synthesize vocal lyrics. (Apparently, MIDI guitar isn’t realistic sounding either.)
Most of the background music you hear in movies and on TV is MIDI… If you hear background-orchestra music in a modern movie or TV program, it’s very-likely not a real orchestra. MIDI is also used a LOT in pop, rap, & techno music.
Typically, you’d use your MIDI application to make an audio file (WAV, MP3, etc.) for “final release”. But your computer can play MIDI directly, and you can find lots of free MIDI files on the Internet if you want to hear some examples. When you play a MIDI file directly with your computer’s soundcard you are hearing whatever virtual instruments that come with your soundcard/driver, which are not the same quality as what you use with a MIDI sequencing application, but it can still sound quite good.
The downside to all of this stuff is that there is big learning curve for the software, and even after learning to use the software, music mixing & production can be very time consuming. With a professional recording, more time is spent in post-production (mixing & editing) than is spent recording. And, somebody who was arguing for using a real drummer once said, “A drummer can play a 3-minute song in 3 minutes. How long does it take you to program MIDI drums for a 3-minute song?”