What is a DAC?
A DAC is a Digital-to-Analog Converter
A DAC [Digital-to-Analog Converter] is a device that converts digital audio information (comprised of a series of 0s and 1s) into an analog audio signal that can be sent to a headphone amp.
In most cases, you can not connect a headphone directly into a DAC. Thus, a headphone amp must serve as the intermediary step between a DAC and your headphones.
The most popular DAC connection method is via USB from a computer. There are also digital feeds available from Optical and Coaxial outputs -- also known as SPDiF connections -- found on CD/DVD players and other audio gadgets that can connect into a DAC. Modern smartphones can even be hooked into outboard amp/DACs, typically by using sundry interconnect cables and adapters.
Remember that lossy (low bitrate) MP3 files will always lack detail and dynamics so the most important thing to improve your headphone sound quality is to rip your digital music in uncompressed formats or at the highest possible bitrate for best sound quality.
So to truly understand how a DAC functions, we should first understand what an analog signal is.
An analog audio signal is a continuously varying voltage that perfectly represents (or is analog-ous) to the continuously varying sound wave that you hear.
For example, a microphone turns incoming sounds into an analog electrical signal representing those sounds; room speakers convert an analog electrical signal back into the original sound (or as close as possible).
But how does one store an analog signal? A half-century ago, one would store an analog signal as a groove on an LP record that moves the needle back and forth during playback to create an electrical analog signal representing the stored sound.
Nowadays, we repeatedly sample and measure the height of the analog signal over time, and then store that series of numbers on a hard-drive or memory of an audio device. This series of 0s and 1s numbers is a digital audio signal.
A CD disc stores these samples as 16-bit binary (1s and 0s) "words" 44,100 times a second - aka 16-bit/44kHz files - but digital audio data can be stored in a variety of sample rates, word sizes, and encoding or compression formats.
In every case, the last thing that happens is the digital numbers get converted back into an analog electrical signal that can be sent to a headphone amp, then your headphones - the device that does this is called a digital to analog converter, or a DAC!