The diagram below shows the overall flow.
There are 3 parts:
๐น Trading
๐น Clearing
๐น Settlement
โถ๏ธ ๐๐ซ๐๐๐ข๐ง๐
Steps 1.1 โ 1.3: The stock buyer and seller place orders via brokers or custodian banks.
Step 2: The brokers execute the orders in the exchange.
โถ๏ธ ๐๐ฅ๐๐๐ซ๐ข๐ง๐
Step 3: The exchange sends execution reports to the clearing agent.
Step 4: The clearing agent match, compare and confirm the trades among brokers or custodians.
โถ๏ธ ๐๐๐ญ๐ญ๐ฅ๐๐ฆ๐๐ง๐ญ
Step 5: The clearing agent calculates settlement obligations and sends to the settlement agent.
Step 6: The securities are delivered in exchange for funds.
You can see there are a lot of steps involved, so currently securities are settled T+2 (trade day plus 2 business days).