Very simple.
You sell the home, and after all of the fee's (and it's a lot, 3% to your agent, 3% to buyers agent, property taxes in arrears (I know I spelled that wrong), warranty as the buyer ALWAYS wants that, standard closing fees) you take what is left. If what is left is more than the balance of the mortgage, you get that cash. If it is less, then YOU have to bring that cash to closing to make up the difference.
I just got a low-ball offer on my Reynoldsburg house, but I would have had to bring 10k to the table (there is nothing in Reynoldsburg on the market with 3 bed / 2 bath / 2 car garage for what they offered). I obviously said no, especially since the market is going to be the best it will be all year this month.