It's called airline revenue management: the science of adjusting fares dynamically and in real time so that airlines can maximize their revenue.
And it's not just a case of simple supply and demand.
Airlines now rely on ever-more sophisticated software that takes into account a broad range of factors, from overall conditions across their global networks, right down to the individual preferences of their passengers.
Seating secrets: How airlines decide what fare you pay - CNN.com