⚠️This platform is for educational purposes only. We are NOT SEBI-registered. DO NOT BUY OR SELL stocks based on recommendations.Read Full Disclaimer|⚠️This platform is for educational purposes only. We are NOT SEBI-registered. DO NOT BUY OR SELL stocks based on recommendations.Read Full Disclaimer|
Market Basics4 min read

How the Stock Exchange Matches Your Buy Order

Understand the mechanics of price-time priority and the order book to make smarter, cost-effective trades.

29 Aug 2026

When you click the 'Buy' button on your broker's app, your order vanishes into the digital network. In a fraction of a second, a confirmation screen pops up: 'Order Executed.' Have you ever wondered who actually sold those shares to you?

It was not your broker, and it was not a random guess by a computer. Instead, the stock exchange ran your order through a highly organized, ultra-fast matchmaking system called the order book.

Meet the Matchmaker: The Order Book

Every stock traded on the exchange has its own digital ledger called an order book. This ledger contains two lists: people who want to buy (the bids) and people who want to sell (the asks).

The exchange does not match people randomly. It follows a strict, fair rulebook known as Price-Time Priority:

  • Price Priority: The exchange always rewards the most competitive prices. The buyer willing to pay the highest price (the Best Bid) and the seller willing to accept the lowest price (the Best Ask) are put at the front of the queue.
  • Time Priority: If two investors want to buy at the exact same price, the one who submitted their order first gets served first.

Inside a Live Order Book

Let us look at a simplified order book for a fictional company, Astra Paints. This table shows the pending orders waiting to be matched at the exchange:

SidePrice (₹)QuantityQueue Position
Sell (Ask)150.201503rd in line to sell
Sell (Ask)150.101002nd in line to sell
Sell (Ask)150.05501st in line to sell (Best Ask)
Buy (Bid)149.902001st in line to buy (Best Bid)
Buy (Bid)149.801502nd in line to buy
Buy (Bid)149.703003rd in line to buy
Astra Paints Order Book Liquidity Depth
Bids (Buyers)Asks (Sellers)
0108216324Bids (Buyers) — ₹149.70 (Bid): 300Asks (Sellers) — ₹149.70 (Bid): 0₹149.70 (Bi…Bids (Buyers) — ₹149.80 (Bid): 150Asks (Sellers) — ₹149.80 (Bid): 0₹149.80 (Bi…Bids (Buyers) — ₹149.90 (Bid): 200Asks (Sellers) — ₹149.90 (Bid): 0₹149.90 (Bi…Bids (Buyers) — ₹150.05 (Ask): 0Asks (Sellers) — ₹150.05 (Ask): 50₹150.05 (As…Bids (Buyers) — ₹150.10 (Ask): 0Asks (Sellers) — ₹150.10 (Ask): 100₹150.10 (As…Bids (Buyers) — ₹150.20 (Ask): 0Asks (Sellers) — ₹150.20 (Ask): 150₹150.20 (As…
Notice the clear gap between the highest buyer bid (₹149.90) and the lowest seller ask (₹150.05), which represents the bid-ask spread. · Illustrative example

Step-by-Step: Walking a Trade Through the Book

Imagine you want to buy shares of Astra Paints. You place a Limit Order to buy 80 shares at a maximum price of ₹150.10. Here is exactly how the exchange matches your order, step by step:

How Your Order Gets Filled
  1. Step 1: The exchange receives your buy order for 80 shares with a limit price of ₹150.10.
  2. Step 2: It checks the best available sell price. The first seller in line is offering 50 shares at ₹150.05. Since ₹150.05 is lower than your maximum limit of ₹150.10, the exchange matches you with this seller.
  3. Step 3: You successfully buy 50 shares at ₹150.05. Your order still needs 30 more shares to be complete (80 - 50 = 30).
  4. Step 4: The exchange looks at the next seller in line, who is offering 100 shares at ₹150.10. Since this matches your limit price, the exchange buys the remaining 30 shares from this seller.
  5. Step 5: Your order of 80 shares is now fully complete. The second seller now has 70 shares left waiting in the queue (100 - 30 = 70).

Because of price priority, you actually saved money on your first 50 shares by getting them at ₹150.05 instead of your maximum limit of ₹150.10.

Why This Matters for Your Trades

Knowing how the order book works helps you make smarter trading decisions. If you place a 'Market Order' instead of a 'Limit Order,' you tell the exchange to buy immediately at whatever price is available. If you wanted 500 shares, a market order would sweep through multiple sellers, buying at ₹150.05, then ₹150.10, and then ₹150.20, driving up your average cost. This is called slippage.

Average Execution Price by Market Order Size
15015015015050 Shares80 Shares150 Shares200 Shares300 SharesAverage Price Paid (₹) — 50 Shares: 150Average Price Paid (₹) — 80 Shares: 150Average Price Paid (₹) — 150 Shares: 150Average Price Paid (₹) — 200 Shares: 150Average Price Paid (₹) — 300 Shares: 150Average Price Paid (₹) 150
Notice how larger buy orders force the matching engine to sweep higher price levels in the order book, driving up your average cost. · Illustrative example
Remember this

Always use limit orders when trading stocks with low volume to prevent the order book matching engine from filling your order at unexpectedly high prices.

When you search for any stock on stock-analyze.com, you can view the live bid-ask spread and liquidity metrics directly on the stock's real-time analysis page to ensure you always trade at the best possible price.

Put this lesson to work

See these numbers live on any NSE/BSE stock — fundamentals, technicals and an AI verdict on one page.

Analyze a stock free