In practice in most cases you can. Although most Chinese embassy websites say "without leaving the airport", Chinese LAW says you CAN:
http://www.ebeijing.gov.cn/feature_2/ResidinginBeijing/LegalProcedures/LawsRegulations/t1034962.htm
http://www.china.org.cn/english/LivinginChina/184914.htm
http://gr.china-embassy.org/eng/lsqw/lsfg/t146145.htm
"Article 8 Aliens may be exempt from going through the procedures for obtaining a transit visa if they hold a through ticket and have booked seats on international airliners flying directly through China, and will stay in a transit city for less than 24 hours without leaving the airport; aliens who wish to leave the airport shall apply to the border inspection office for permission to stay."
But as you know, laws are not always properly enforced. They are many travelers on transit without a visa for under 24 hrs, left the airport and came back and flew out.
My suggestion: if you must stay in a hotel overnight, get a visa before you leave. If on the other hand you can survive staying inside the airport if the stars don't align(and Chinese law not properly enforced), save the visa fee and try your luck.
Edited: 9 years ago