Foundations5 min read

How a Stock Exchange Works

An exchange is a matching engine surrounded by rules. Understanding the order book, the market maker and the auctions explains why liquidity appears and disappears at particular moments.

MadStockAlerts Research · Updated August 28, 2026

What to take away

  • An exchange matches orders by price first and time second.
  • The order book is the live queue of unfilled limit orders on both sides.
  • A market maker quotes continuously and is compensated by the bid-ask spread it earns.
  • US equities trade across many venues at once, which is why a consolidated NBBO exists.
  • The closing auction is the single largest liquidity event of the trading day.

MAD Academy Training Video · 0:45

Where Your Order Actually Goes

Pressing buy does not send your order to an exchange floor. It enters a matching engine that pairs it against a resting order.

This lesson is part of a Stock Alerts + Tools plan.

See the library

Price-time priority

The core of an exchange is a rule for deciding whose order gets filled. Almost every equity venue uses price-time priority: the best-priced order wins, and among orders at the same price the one that arrived first wins.

That single rule produces most of the behaviour traders observe. It is why a large resting order at a round number can absorb selling for a long time before giving way, and why being early to a price matters as much as being right about it. It is also why the queue at a popular level is long: everyone who wants that price has to wait behind everyone who wanted it sooner.

The engine itself is indifferent to who is on either side. It has no view about the company, applies the same rule to a hundred shares and to a hundred thousand, and matches whatever crosses.

The order book

The order book is the list of resting limit orders at each price on both sides. The highest price anyone is currently willing to pay is the bid; the lowest anyone will accept is the ask. Between them sits the bid-ask spread, and nothing trades inside it until someone crosses.

SidePriceShares resting
Ask42.123,100
Ask42.111,400
Ask42.10900
Bid42.082,600
Bid42.075,000
Bid42.058,200

In that book the spread is two cents. A market order to buy 1,200 shares takes the 900 available at 42.10 and then reaches up for 300 more at 42.11, filling at an average of about 42.1025. The screen said 42.10; the fill did not. That difference is where the cost of immediacy shows up, and it grows with the size of the order.

The shape of the book matters as much as the spread. A tight two-cent quote with 900 shares behind it is not the same market as a tight two-cent quote with 90,000 shares behind it, and only the second one can absorb an institutional order without moving.

One side of the book against the other
One side of the book against the other42.123,10042.111,40042.1090042.082,60042.075,00042.058,200Asks: the lowest price sellers will acceptThe spread: nothing trades in hereBids: the highest price buyers will paySize at each price is the depth
Bar length is the size resting at each price. Nothing trades between the best bid and the best ask until somebody crosses.

Most retail platforms display only the top of the book: the best bid, the best ask, and sometimes the size at each. Depth beyond that is a separate, usually paid, data product. A quote that looks reassuringly tight may have very little behind it.

Market makers

A market maker is a firm that commits to quoting both sides continuously, so there is always something to trade against. It is compensated by earning the spread across many round trips, and it manages the risk of holding inventory it did not want.

The economics are thin and repetitive. Earning a cent per share thousands of times a day is a real business only if the inventory risk is controlled, and that risk is the probability that whoever just sold to the market maker knew something it did not.

When volatility rises, that risk rises with it, and the rational response is to quote wider and in smaller size. This is why spreads widen exactly when a stock is moving fastest, which feels perverse to a trader who wants to act and is entirely mechanical. Nobody withdrew liquidity to be difficult; the price of providing it went up.

Auctions

The regular session opens and closes with an auction rather than continuous trading. Orders accumulate over a period, and a single price is chosen that maximises the number of shares that can be matched. Everyone who transacts in the auction gets that same price.

The closing auction in US equities is by far the largest liquidity event of the day, frequently several percent of a stock's entire daily volume in one print. The reason is structural: index funds and benchmarked managers are measured against the official close, so transacting at that price is the only way to avoid tracking error.

The official closing price used by data vendors, index providers and settlement systems is the auction price, not the last continuous trade. Prints after the bell do not change it, which is why a chart's daily close and an after-hours quote can differ and both be correct.

Many venues, one best price

US equities do not trade in one place. Orders route across a dozen or more exchanges plus a set of off-exchange venues, and regulation requires that an order not be executed at a price worse than the best available elsewhere. The consolidated best prices are published as the NBBO, which is the quote most retail screens display.

Off-exchange execution, sometimes called internalisation, means a share of volume never touches a public order book at all. A wholesaler matches retail orders against its own inventory, frequently at a price slightly better than the NBBO. The trade is reported publicly afterwards but it was never displayed as an available quote.

The proportion of a stock's volume traded off-exchange is disclosed and is a useful read on how much of its activity is actually visible in the book. A name with a very high off-exchange share has a public order book that describes only part of what is happening.

Quoted width alongside the share of volume trading away from exchanges, ranked across the market rather than for one ticker.

Spread and off-exchange, market-wide — for members

Halts

Trading can stop. A regulatory halt pauses a stock pending news so that the information reaches everyone before anyone trades on it. A volatility halt triggers automatically when price moves outside a band in a short window, and lasts a few minutes.

Both matter for anyone holding a position, because a halt removes the ability to act while the reason for wanting to act is still developing. A stop order does not protect against a halt: it can only execute when the market reopens, at whatever price the reopening auction produces.

Primary sources

Educational content only. MadStockAlerts provides market commentary, research, and educational content. It is not personalized investment advice, and nothing here is a recommendation to buy or sell any security. Trading and investing involve substantial risk, including loss of capital. See the Risk Disclosure and Customer Agreement.