Now, let's jump in to see the mechanics of a stock price change.
To see how stock prices change, we are going to slow down real time to be able to inspect the mechanics that take place in fractions of a second on the real exhanges. For our example, we are looking at the trading of XYZ stock which recently traded at $50 per share at 10:00:00.
Let's say for the sake of example that at 10:00:01, the bid for XYZ stock is $49 and the ask is $51. This means that there is someone who will buy XYZ stock right now for $49 and someone who will sell XYZ stock right now for $51. If there are no new orders, then there will be no trades. This state can stay the same or change as investors offer different bid and ask amounts and as trades are executed.
Now, we'll say that nothing changes until one second later at 10:00:02 when a new investor phones in a market order to his broker. A market order is a trading instruction to execute the order at "the market price." Another way to view a market order is that it is an order which commands a trade to be made at whatever price is necessary to ensure that the order is completed now.
If the order is a sell order, then the trade will execute at $49 per share. In other words, the price of XYZ stock at 00:02 would be $49 because that is the best price available from someone willing to buy the stock being offered. But, if it is a buy order, then the trade will execute at $51 because that is the best price being offered by someone willing to sell the stock and the price at 00:02 would be $51.
On the real stock exchange this can all happen many times in a single second for a heavily traded stock, or maybe only a few times per day for a thinly traded stock. Either way, the stock's price per share has changed, going either higher or lower in response to the market order issued. The next move for the stock price is a function of the remaining bids and asks on the stock and other orders that are executed in one way or another.
Also, note that with the stock price having moved the bid or ask may move as well.
For example, if the order was a buy order and moved the stock's price to $51 per share, then the bid might move up as well, either due to the previous investor revising his bid upwards to reflect the new price of the stock, or due to another investor inserting a new order which effectively causes an increase in the bid.
The difference between the bid and the ask is called the spread.