Are capital gain taxes calculated on the gross profit or would it be on the amount we received after deducting the closing costs and brokerage commissions etc.?

eg: Purchased amount is 500K, stayed for 1 year 1 month, Sold it for 600K, Profit was 100K, but had to pay approx 40K as closing cost and commissions, what will the capital gain tax be calculated on