In your store management area, go to Products and click on a product you want to edit. In the product settings, scroll down a bit and toggle the Track quantity button to enable inventory tracking. Then, specify the stock quantity:
You can also specify the stock for each product option individually. Click Manage variants:
Enable Track quantity and specify the quantity in stock:
The amount is automatically reduced on every sale. Similarly, if you cancel an order, products are automatically restocked.
If the maximum quantity is reached, a client won't be able to add the product to the cart.