The fundamental principle in freeze-drying is sublimation, the shift from a solid directly into a gas. Just like evaporation, sublimation occurs when a molecule gains enough energy to break free from the molecules around it. Water will sublime from a solid (ice) to a gas (vapor) when the molecules have enough energy to break free but the conditions aren't right for a liquid to form.
There are two major factors that determine what phase (solid, liquid or gas) a substance will take: heat and atmospheric pressure. For a substance to take any particular phase, the temperature and pressure must be within a certain range. Without these conditions, that phase of the substance can't exist. The chart below shows the necessary pressure and temperature values of different phases of water.
You can see from the chart that water can take a liquid form at sea level (where pressure is equal to 1 atm) if the temperature is in between the sea level freezing point (32 degrees Fahrenheit or 0 degrees Celsius) and the sea level boiling point (212 F or 100 C). But if you increase the temperature above 32 F while keeping the atmospheric pressure below .06 atmospheres (ATM), the water is warm enough to thaw, but there isn't enough pressure for a liquid to form. It becomes a gas.
This is exactly what a freeze-drying machine does. A typical machine consists of a freeze-drying chamber with several shelves attached to heating units, a freezing coil connected to a refrigerator compressor, and a vacuum pump.
With most machines, you place the material to be preserved onto the shelves when it is still unfrozen. When you seal the chamber and begin the process, the machine runs the compressors to lower the temperature in the chamber. The material is frozen solid, which separates the water from everything around it, on a molecular level, even though the water is still present.
Next, the machine turns on the vacuum pump to force air out of the chamber, lowering the atmospheric pressure below .06 ATM. The heating units apply a small amount of heat to the shelves, causing the ice to change phase. Since the pressure is so low, the ice turns directly into water vapor. The water vapor flows out of the freeze-drying chamber, past the freezing coil. The water vapor condenses onto the freezing coil in solid ice form, in the same way water condenses as frost on a cold day. (See How Refrigerators Work for more information on condensers and refrigeration coils.)
This continues for many hours (even days) while the material gradually dries out. The process takes so long because overheating the material can significantly change the composition and structure. Additionally, accelerating the sublimation process could produce more water vapor in a period of time then the pumping system can remove from the chamber. This could rehydrate the material somewhat, degrading its quality.
Once the material is dried sufficiently, it's sealed in a moisture-free package, often with an oxygen-absorbing material. As long as the package is secure, the material can sit on a shelf for years and years without degrading, until it's restored to its original form with a bit of water (a very small amount of moisture remains, so the material will eventually spoil). If everything works correctly, the material will go through the entire process almost completely unscathed!