Cost of Goods Sold, or Direct Costs, is the net expenses spent on producing the goods that are sold by the company. These include the cost of materials and labor. Other costs like distribution costs and sales are excluded and these are known as indirect costs.
The formula for calculating COGS:

In the above formula, starting inventory refers to the remainders of the previous sales period, and inventory at the ending is the leftover goods after the current sales period. The ending inventory of each accounting year is mentioned under the inventory section of the balance sheet.
The final inventory is subtracted from the sum of the materials bought during the current period and the previous stock. This number gives the COGS. An increase in the COGS will negatively impact the net profit of the company, due to the increase in the cost of production or acquisition of inventory.