There are many factors that can lead to mildew or moldy smells in a basement. The first and most common is the presence of water either as moisture or excessive humidity. The next is a total lack of air movement. If these two are combined there will either be a mold build-up or the likelihood of one.
Most commonly mildewy or moldy basement smells are due to wet foundation walls and the presence of finishing materials such as carpet and drywall. The building materials are consistent food supply and will aid mold growth if given enough water supply.
There are two basic ways to remove a moldy smell.
1. The prevention of the water or moisture presence. This is the most desired cure and the best starting point of removing the mold growth and of course the moldy smell. This may involve plumbing repairs, waterproofing either interior or exterior, or balancing of HVAC systems among other cures.
2. The removal of building materials. This is a less desired approach. But removal of the food that is aiding the mold growth if the water problem cannot be solved will slow or prevent further mold growth even if the cause of the moisture problem is not cured.