How to we get physical sounds into a digital format?
We call the process of taking a physical, or "analog", signal to a digital signal "Analog-to-Digital Conversion", or ADC.
A sound emits from a musical instrument or device. A microphone takes the pressure in the air into a diaphragm. The movement of the diaphragm indicates the change in amplitude over time. The energy from the diaphragm travels to a digital converter. The converter changes the the amplitude over time into a waveform. Sometimes, this digital converter can also provide electric current to the microphone to operate, and in this case we call the converting device a preamp. The digital converter samples the analog waveform from the microphone in a process known as quantification. The digital converter measures the continuous analog signal at regular intervals and converts the samples to an integer representing the amplitude at that moment in time. Finally, the converter sends the array of integers representing the sound into the computer.
Physical sounds have two areas: compression and rarefaction. In compression, the air molecules are dense, and in rarefaction, the air molecules are spaced apart. So for any given frequency, you need two pieces of data to represent these two stages. You need double the sampling rate as the highest frequency in the sound in order to represent the sound. We can reasonably expect no human can hear frequencies above 22,050 Hz. Therefore, album quality audio has a sampling rate of 44,100 times per second. The idea that the sampling rate needs to be twice the highest audible frequency stems from the Nyquist-Shannon sampling theorem.
We refer to the process of returning to an analog signal as "Digital-to-Analog Conversion", also known as DAC.
To go back to a physical sound for playback, a device changes the array of integers back into an analog signal first, and then this analog signal is sent to the speakers. The speakers move their diaphragms to match the analog signal, which creates changes in pressure in the air to create sound.