What Is an Earnest Money Deposit?

Earnest money is a sum of cash you pay before closing on a home, to show the seller you're serious. How does it work?