A dehumidifier is essentially a refrigerator that forgot to get fully dressed. Really. The basic mechanical function of a dehumidifier is the same as a refrigerator. Compression and expansion of a gas is used to lower the temperature of metal coils to freezing temperatures.
However, instead of the cooling action being directed into a closed box, a dehumidifier is designed to blow warm moist room air over these cold coils. The moisture in the room air condenses on the coils to become liquid water. The water then drips into a drip collection pan, or to a drain. The room air, now freed of much of its moisture, returns to the room slightly warmer than it was.