When there is a difference between the two ... no trading occurs.
Let's look at an example: Investor A, B, C, and D all buy/sell shares of company X. Investor A wants to sell 10 shares at $20 a share (Ask price $20 x10). Investor B wants to buy 15 shares at $10 a share (Bid price $10 x15). Since the bid price and ask price are different, no sale is made.
Next Investor C comes along and wants to sell 5 shares at $14 (Ask price $14 x5). Still no sale.
Investor D comes along and wants to buy 5 shares for $14 each. So a sale is finally made. At this point, the stock quote moves to $14. The ask price is $20 x10 and the bid price is $10 x15. No further trading will occur until another investor is willing to buy at $20 or sell at $10.
Another discussion of this topic is shown on this post.