The dealer borrows money through what's called "floor plan financing" in order to keep the inventory on their lots.
Floor plan financing is a type of short-term loan that is paid off in 30 to 90 days, the time it normally takes to sell a car.
A typical new car costs a dealer about $5 to $10 in interest per day. So if a car sits on the lot for 30 days, the dealer will be charged $150 - $300 in interest payments.
This is why dealers want to sell cars as quickly as possible - to reduce their financing costs and increase profits.
Most manufacturers reimburse these finance costs through what is called "dealer holdback". This is usually 2 - 3% of the invoice price of the vehicle.
On a typical $28,000 car, a 2% holdback would amount to around $550. If the dealer sells this car in 30 days and incurs financing costs of $300, then they will make a profit of $250 on the holdback.
If a car has been sitting on the lot for a long time, the financing costs will eat up all the potential profit and the dealer may have to sell the car at a loss.
You can usually get the best deals on cars that have been sitting on the lot a long time since dealers are anxious to get rid of them and cut their losses.