A trade can be executed in a variety of way. Where and how an order is executed can impact the overall costs of the transaction, including the price paid for the stock.
Investors who trade through a broker do not have a direct connection to the securities markets. Their order is sent over the internet to the broker, who decides which market to send it to for execution. The same process happens when someone calls his or her broker to place a trade.