Cost of goods sold = beginning inventory + net purchases − ending inventory. Formula, step-by-step example, and common mistakes for your SMB.
A practical guide to understanding how the cost of goods sold is determined in a Mexican SME, with a visible formula, accounting steps, and applicable examples.
The cost of goods sold is not "accounting data for later." It is the bridge between what you buy, what you actually sell, and the gross margin you have left. If the calculation is wrong, the price can seem profitable when it is not.
How is the cost of goods sold calculated? Formula and step-by-step example
Direct answer: the cost of goods sold is calculated by adding the beginning inventory and the net purchases of the period, and subtracting the ending inventory. The result is the value of the merchandise that you did sell or consume, not what you bought. Net purchases are your purchases plus freight, minus returns and discounts.
Cost of goods sold formula
Cost of goods sold = beginning inventory + net purchases − ending inventory
Net purchases = purchases + freight − returns − purchase discounts
Example in MXN: beginning inventory $30,000 · purchases $45,000 · freight $2,000 · returns $1,500 · discounts $500 · ending inventory $28,000.
Net purchases: $45,000 + $2,000 − $1,500 − $500 = $45,000.
Cost of goods sold: $30,000 + $45,000 − $28,000 = $47,000.
If you want to calculate it at the close of a month, quarter, or year, the practical order is as follows:
Take the beginning inventory of the period with which you opened the month or the fiscal year.
Add net purchases: purchases of the period + direct acquisition freight − returns − purchase discounts.
Determine the ending inventory with a physical count or with a reliable system adjusted for actual shrinkage and write-offs.
Subtract the ending inventory to obtain the cost of goods sold for the period.
How are net purchases calculated?
Net purchases are what the merchandise that entered during the period actually cost you. Start from total invoiced purchases, add freight and cartage to bring it to your warehouse or branch, and subtract returns to suppliers and discounts or rebates on purchases. In the example above: $45,000 + $2,000 − $1,500 − $500 = $45,000. If you only use "the invoices of the month," the cost of goods sold will be inflated or underestimated.
Those $47,000 are the cost of goods sold for the period. In accounting terms, when merchandise is sold, its book value is recognized as an expense in the same period as the related revenue, as summarized by AccountingCoach on cost of goods sold.

What exactly is the cost of goods sold and why is it crucial for your SME?
The cost of goods sold is the value of the goods or supplies that were actually consumed or sold during a period. It does not represent everything you paid that month, but the portion of the inventory that actually went out to generate revenue.
Base formula: beginning inventory + net purchases − ending inventory.
To calculate it at the close of a period, follow this minimum sequence:
Identify the beginning inventory with which the period opened.
Add net purchases from the same period.
Value the ending inventory that was left unsold or unconsumed.
Subtract that ending inventory to obtain the cost of goods sold.
In trading businesses, such as pharmacies, boutiques, hardware stores, and grocery stores, this formula usually resolves almost the entire calculation for the period. In businesses that transform inputs, such as restaurants, bakeries, and light production workshops, direct production costs also intervene, such as direct labor and, in some cases, indirect manufacturing costs that must be allocated with accounting criteria. This is the point that changes the result the most: two businesses with the same purchases can report different costs if one only resells and the other produces.
Why does it matter so much? Because the data directly hits the gross margin. If the cost of goods sold goes up and the price is not adjusted, the gross profit is compressed. If the calculation is incomplete, you might believe a product is making money when in reality it barely covers its cost.
Key formula to calculate the cost of goods sold
Rather than memorizing the formula, it is better to understand what goes in and what does not go into each component so that the calculation is replicable in a spreadsheet or in your monthly close.
1. Beginning inventory
This is the value of the inventory available at the beginning of the period. It must come from the previous close and use the same valuation method.
Includes: merchandise for sale, raw materials, work in progress, or finished goods depending on the type of business.
Does not include: rent, advertising, administrative salaries, sales commissions, or general services.
2. Net purchases
They are not just "the invoices of the month." The useful calculation is:
Net purchases = purchases + direct freight − returns − purchase discounts
Includes:
purchases of merchandise or direct inputs
freight and cartage to put the merchandise in the warehouse or branch
expenses directly attributable to acquiring the inventory
Excludes:
sales expenses to the final customer
marketing campaigns
rent of the premises
administrative salaries
interest or financial expenses
3. Ending inventory
This is the value of what is left at the close and has not yet been sold or consumed. Ideally, it is determined by a physical count and reconciliation against the system. In our review, the most costly mismatch appeared when the business used theoretical inventory without validating actual shrinkage.
Sequential calculation with example
Assume a monthly close for a coffee shop:
Beginning inventory: $20,000
Purchases of the month: $50,000
Acquisition freight: $3,000
Returns to supplier: $2,000
Purchase discounts: $1,000
Ending inventory: $18,000
Step 1. Calculate net purchases
$50,000 + $3,000 − $2,000 − $1,000 = $50,000
Step 2. Add beginning inventory + net purchases
$20,000 + $50,000 = $70,000
Step 3. Subtract ending inventory
$70,000 − $18,000 = $52,000
Result: the cost of goods sold for the month is $52,000.
If that same coffee shop sold $160,000 in food and beverages, it can now compare how much of the revenue went into direct cost and how much remained as gross margin. In food businesses, this analysis is usually also followed as a percentage of sales (food cost); if you want to apply it to each product, review how to calculate the cost of a dish.
Data entry errors that alter the result
Using theoretical inventory instead of physical count when there is shrinkage, expiration, or theft.
Excluding shrinkage and write-offs because "they are not recorded yet"; this inflates ending inventory and artificially lowers cost.
Mixing operating expenses with direct costs, such as rent or marketing.
Omitting purchase freight which is indeed part of the acquisition cost.
Changing valuation methods without consistency, which makes closes incomparable.
The fundamental difference: cost of goods sold vs. cost of purchases
This is where many SMEs get confused, and the distinction does matter for the financial health of the business.
The cost of purchases is simply the money you disbursed to acquire new inventory. In contrast, the cost of goods sold focuses only on the value of the inventory that was actually sold or consumed in the period. If you want to dive deeper, understanding how the cost of purchases is calculated helps to better organize inventory control.
Imagine you bought $50,000 in merchandise for your store in Monterrey. If at the end of the month you only sold half, your cost of goods sold will be approximately $25,000 —not counting the inventory you already had at the beginning—. Confusing these two figures can lead you to think you are earning less than you actually are, or vice versa.
Why should this calculation be a priority?
Mastering the determination of the cost of goods sold allows you to answer questions that directly affect the future of the business:
Are my prices profitable? If the selling price barely covers the cost, you are not building a sustainable business. The cost of goods sold is the basis for setting healthy margins.
Which products actually leave me a profit? By breaking down the cost per product, you can identify which ones leave a higher margin and which ones, even if they rotate well, contribute little to profit.
Do I have inventory leaks? A cost of goods sold that shoots up for no apparent reason can be a sign of shrinkage, waste, theft, or a bad purchasing strategy.
In practice, ignoring the cost of goods sold is operating without a compass. You can see movement in cash, but not know if the business is moving towards profitability or just spinning on deceptive numbers.
Choose the right inventory valuation method for your business
The valuation method is not a minor technical detail: it modifies the reported cost of goods sold and, with that, the gross profit of the period. If you buy the same product at different prices during the month, the way you allocate those costs to what is sold changes the accounting result. Technical references for inventory under IFRS allow, among others, specific identification, FIFO, and weighted average cost, as summarized in this excerpt from Wiley on inventory valuation.
Method | How it allocates costs | When it is suitable | Effect under inflation | Practical/fiscal treatment in Mexico |
|---|---|---|---|---|
FIFO (PEPS) | Allocates the oldest inventory costs to sales first. | Businesses with natural rotation by age, expiration, or clear batches: food, pharmacy, retail with frequent replenishment. | Usually shows lower cost of goods sold and higher gross profit than methods with more recent costs. | It is a practical and widely used method. It favors operational consistency when physical flow also goes by age. |
Weighted average | Calculates an average cost among all available units and that value is applied to outflows. | SMEs with many recurring purchases of homogeneous products and little need to track batch by batch. | Smooths price variations; typically leaves an intermediate result between FIFO and more recent costs. | Very useful for administrative control and stable closes. Requires discipline to recalculate the average correctly. |
LIFO (UEPS) | Allocates the most recent costs to sales first. | It is used more for comparative analysis than for daily operations in Mexico. | In inflation, it tends to show higher cost of goods sold and lower gross profit. | In Mexican tax practice, it is not usually the recommended operational reference for SMEs; it is advisable to validate it with an accountant before using it for formal reports. |
In a Mexican SME that buys recurring merchandise —for example, a store, coffee shop, or small pharmacy— our editorial recommendation usually leans towards FIFO or weighted average, not out of trend but for control. FIFO aligns well with perishable inventories and operations where stock age matters; weighted average simplifies closes when the catalog is broad and receipts are frequent. The decisive thing is not to choose "the perfect method," but to use one consistently, document it, and review it with your accountant so that the cost of goods sold calculation does not change criteria every month.
Applying any of these methods correctly requires a very organized system. Good inventory control is the basis for accurate valuation. If you want to delve into best practices, review our guide on inventory registration.
Theory helps, but the real test to understand how the cost of goods sold is determined occurs in daily operations. Let's leave abstract concepts aside for a moment and perform the calculation in two scenarios that any Mexican SME will recognize immediately.
These examples clearly show how the classic formula —beginning inventory + purchases − ending inventory— becomes a practical tool in business operations.
Case 1: a taco shop in Mexico City
Let's take "El Sazón Chilango," a taco shop in Roma that wants to check if its line of tacos al pastor really leaves the expected margin. This example works well because it allows going from unit cost to period cost and then to gross profit, which is where the data starts to be useful for making decisions.
1. Unit cost of the taco
Pork meat al pastor (100 g): $5.00
Corn tortilla: $0.50
Pineapple, onion, and cilantro: $0.75
Prorated sauces and lime: $0.50
Raw material per taco: $6.75
Now we add direct labor. If the taco maker earns $8,000 per month and spends half of his shift producing tacos al pastor, $4,000 is attributed to that line. If during May 10,000 tacos were prepared, the direct labor per unit is:
$4,000 / 10,000 = $0.40 per taco
Total unit cost:
$6.75 + $0.40 = $7.15 per taco
2. Determination of the cost of goods sold for the period
Now we move from unit cost to monthly close:
Beginning inventory as of May 1: $8,000 in meat, tortillas, sauces, and other direct inputs.
Purchases of the month: $25,800
Returns to supplier: $300
Net purchases: $25,500
Ending inventory as of May 31: $6,500 according to physical count.
Step-by-step calculation:
Step 1. Beginning inventory + net purchases
$8,000 + $25,500 = $33,500
Step 2. Subtract ending inventory
$33,500 − $6,500 = $27,000
Cost of goods sold for May: $27,000
3. Bridge to sales and gross profit
If in May the taco shop sold 10,000 tacos at $14 each, its sales for the period were $140,000.
Gross profit = sales − cost of goods sold
$140,000 − $27,000 = $113,000
That bridge is what makes the calculation useful: if the cost goes up due to shrinkage, expensive purchases, or poorly controlled portions, the margin deteriorates even if gross sales look healthy. In our review, this type of business usually improves the most when it links recipes, purchases, and physical inventory in the same monthly close.
Where does each piece of data come from?
The beginning and ending inventory must come from the physical count of inputs.
The purchases and returns must come from the system, invoices, or integrated POS.
The direct labor comes from the payroll record or the documented allocation of kitchen staff.
Case 2: a clothing boutique in Baja California
Now let's change industries and bring the formula to the retail world. "Arena & Sol" is a boutique in Ensenada that sells handcrafted clothing from local suppliers. Its main challenge is tracking the actual cost of a batch of embroidered blouses, from purchase to sale.
This example serves to show how additional costs, like freight, form part of the acquisition cost and affect the determination of the cost of goods sold.
Batch purchase: they acquire 50 blouses from an artisan in Yucatan. The cost per piece is $300, so the base cost of the batch is $15,000.
Shipping cost (freight): moving the batch from Yucatan to Ensenada costs $1,000. It is not an operating expense; it is a direct cost that must be added to the inventory value.
Total acquisition cost: $15,000 for blouses + $1,000 for freight = $16,000.
Unit cost: $16,000 / 50 blouses = $320 per blouse. That is the actual cost per item in store.
With that correct unit cost, the boutique can now calculate its quarterly cost of goods sold.
Beginning inventory (January 1): the store had merchandise valued at $30,000.
Net purchases: during the quarter, it bought the batch of blouses and other items for a total of $50,000 —already including all freight—.
Ending inventory (March 31): after the physical count, the unsold merchandise has a value of $22,000.
The quarterly cost of goods sold is determined as follows:
$30,000 + $50,000 − $22,000 = $58,000
For "Arena & Sol," knowing that its quarterly cost of goods sold was $58,000 gives it visibility to analyze its performance, adjust prices, and better plan its next purchases.
The impact of new consumption habits
What both examples do show is that, beyond the cost of goods sold formula, the key lies in keeping an impeccable record of each direct cost. At that point, a point-of-sale system that automates product inventory control stops being a luxury and becomes an operational ally for any business that wants to work with precision and protect its profitability.
If you run a restaurant, this calculation is the starting point of our guide to digitizing your restaurant, and a dashboard with sales, costs and margin lets you review it every week without doing the math by hand.
Common mistakes when calculating the cost of goods sold and how to correct them
An incorrectly calculated cost of goods sold is one of the most silent and dangerous financial leaks for a business. It leads to setting prices that do not cover the actual cost and making strategic decisions based on incorrect information.
In our review, we detected recurring pitfalls in commercial and retail SMEs. The good news is that identifying them is the first step to correcting them and protecting the margin.
Mixing operating expenses with cost of goods sold
This is, without a doubt, the most classic mistake. It is easy to put the rent of the premises, the manager's salary, social media ads, and the cost of the merchandise in the same bag. But they are different things.
The cost of goods sold only includes costs directly linked to the product you sell. Everything else —electricity, water, administrative salaries, marketing— are operating expenses necessary for the business to function, but not to produce or acquire that specific unit sold.
The correction is simple, though it requires discipline: separate accounting accounts.
In cost of goods sold should appear: raw materials, direct labor, freight to bring merchandise to the warehouse, and directly attributable import costs.
In operating expenses goes the rest: administration, sales, rent, utilities, advertising, among others.
Think of it this way: in a coffee shop in Monterrey, the coffee, milk, cups, and a portion of the barista's salary associated with preparing drinks can indeed be linked to the direct cost. The Instagram campaign to attract customers and the rent of the premises cannot.
Ignoring shrinkage and obsolete inventory
What do you do with the croissants that didn't sell today, the milk that expired, or the seasonal t-shirts that are no longer rotating? If they simply "disappear" without an accounting record, your numbers start to lie.
In these cases, the ending inventory appears higher than reality, which artificially lowers the cost of goods sold and inflates a gross profit that does not exist in cash.
Shrinkage is a cost, not an eventuality. Whether due to expiration, damage, or theft, its value has to impact your finances. Ignoring it only creates a false sense of profitability.
To correct it, you need a clear process for recording write-offs:
Classify write-offs: "shrinkage due to expiration," "damaged product," "shoplifting."
Record their value: when you write off a product, its cost must impact the corresponding period.
Lean on technology: a good inventory system facilitates these write-offs and keeps numbers updated. If you don't use one yet, it is worth checking how inventory software can help you.
Forgetting indirect production costs
If your business manufactures or transforms products, the cost goes beyond raw materials. A frequent blind spot is the depreciation of machinery used for production.
Imagine a small artisan ice cream shop in Puebla that invested $150,000 MXN in an ice cream making machine. If its estimated useful life is 5 years, every year it loses $30,000 of value.
That cost, although it does not imply a monthly cash outflow, does represent an actual production cost. It must be distributed among the liters or units manufactured and sold.
The practical output here is to review the issue with your accountant: calculate the depreciation of productive assets —ovens, mixers, sewing machines— and define a criterion to allocate a portion to the cost of goods sold. Failing to do so usually underestimates what it actually costs to produce.
How Swirvle automates the calculation of your cost of goods sold
If you have ever tried to control inventory and costs with spreadsheets and loose notes, you already know the problem: wasted hours, data entry errors, and little clarity on how much you actually earn.
This is where technology becomes an ally. An all-in-one platform like Swirvle doesn't just record sales; it helps organize operations and automate the determination of the cost of goods sold from connected data.
Total connection from your point of sale
It all starts at the counter. The engine of this automation is the point of sale system, which stops being a simple cash register to become an operational hub for the business. Every time you register a sale, the system updates relevant information for inventory and cost.

Sale made, inventory updated. If you sell a garment, a grocery item, or a drink, the system deducts that unit from stock at that moment.
Valuation without manual calculation. The platform can apply the valuation method you have configured, consistently between periods.
Let's think of a store in Mexico City. With each sale, the system knows what product went out and at what cost it was recorded in inventory, helping to link the outflow with its corresponding purchase cost. That improves financial visibility and operational order.
Smart recipes: a help for food businesses
And what if your business is more complex, like a coffee shop, restaurant, or ice cream parlor? Calculating the cost of a dish with multiple ingredients is usually one of the biggest operational headaches. The logic of recipes helps precisely at that point.
Imagine a coffee shop in Puebla. Inside the platform, you define the recipe for a "large cappuccino":
30 grams of coffee beans
200 ml of whole milk
1 12 oz cup
1 cup lid
If the system already knows the unit cost of each input, upon registering the sale of the cappuccino it can automatically sum the cost of those components, record it as the cost of goods sold for that beverage, and deduct the precise quantities from the inventory of each input. The result is a much clearer view of the margin per product.
Attribution by branch, campaign, or even by seller
Knowing the total cost of goods sold is useful, but the true value appears in the detail. Swirvle allows segmenting that information to better understand the performance of each part of the business.
Here, data stops being just a record and becomes management criteria. Instead of guessing, you can answer questions like: which branch controls its inventory best?, was a promotion actually profitable?, which lines leave more margin?
Analysis by branch: comparing the cost of goods sold between locations can reveal opportunities to negotiate with suppliers, adjust logistics, or detect shrinkage.
Campaign evaluation: a promotion can increase sales but also squeeze margins; measuring both helps to better evaluate the result.
Commercial performance: reviewing which products each team rotates best can provide useful signals for training and sales mix.
With visual dashboards, operations stop depending on estimates and gain traceability to make decisions with more certainty.
Frequently asked questions about the cost of goods sold
Although the formula seems clear on paper, daily operations always bring very specific doubts. In our review, some topics were repeated over and over again among SME owners looking to better understand how the cost of goods sold is determined. Here we clarify the most important ones.
How do you find the cost of goods sold?
Take the beginning inventory of the period, add net purchases (purchases + freight − returns − discounts), and subtract the ending inventory you counted at the close. For example: $30,000 + $45,000 − $28,000 = $47,000 cost of goods sold.
What is the cost of goods sold formula?
Cost of goods sold = beginning inventory + net purchases − ending inventory. For it to work, net purchases must include freight and subtract returns and discounts, and ending inventory must come from a physical count adjusted for shrinkage.
Does the freight I pay to receive merchandise count as cost of goods sold?
Yes. In fact, not including it is a common mistake. Those products would not be in your warehouse, shelf, or kitchen if you had not paid for their transportation. Therefore, freight is part of the acquisition cost of the inventory.
Consequently, it must be added to the value of the products. When you sell a part of that inventory, a proportional portion of that freight ends up impacting the cost of goods sold. It should not be confused with the shipping you charge —or absorb— for the final customer; that already enters into the commercial operation.
What do I do with shrinkage or spoiled inventory?
Shrinkage is a reality in any business with inventory. We are talking about expired, broken, transit-damaged, or even stolen products. Accounting-wise, it must be recorded as an inventory write-off, and its value must impact the period in which the loss is detected.
Ignoring it is deceiving oneself. If you do not record that shrinkage, the ending inventory on the books remains higher than the actual one. That makes your cost of goods sold seem lower than it is and artificially inflates your profit. An ice cream parlor in Yucatan that loses several liters due to a freezer failure needs to reflect it; if it doesn't, it will think it is earning more than it actually is.
Are premises rent and administrative salaries included?
No, and this difference is important. Rent, the salary of the manager or accountant, investment in marketing, and utilities like internet or electricity are operating expenses.
Operating expenses keep the business alive, but they are not directly linked to the production or acquisition of a sold unit. The cost of goods sold is reserved for direct costs.
Mixing both worlds distorts the actual margin per product, which is precisely the reference to know what makes you money and what doesn't.
Why doesn't my cost of goods sold calculation match my accountant's?
This is one of the greatest sources of frustration. Almost always, the difference appears due to one of these reasons:
Different valuation methods: you might be using a simple average for practicality, while the accountant works with FIFO or weighted average under another criterion.
Differences of criteria: your accountant might be including a direct cost that you left out, or vice versa.
Different accounting cutoffs: a few hours' difference at the close can cause a large purchase or sale to fall into different periods.
The solution is to align criteria. Sit down with your accountant, define together which method you will use and which concepts go in and which do not. The most important thing is that both start from the same data source, ideally a sales and inventory system, to avoid two versions of the same operation.
Knowing how to calculate the cost of goods sold is only the first step. The real value appears when you use that information to make better decisions and grow with more control.
Learn how Swirvle's point of sale connects sales, inventory, and costs in your business.
How do we evaluate this cost of goods sold determination process?
To review this topic, we start from the most widely used accounting criterion in businesses with inventory: recognizing the value of the merchandise actually sold as the cost of the period, not simply what was purchased. We contrast the operational formula with accounting practice guides and with typical examples of Mexican SMEs —retail, restaurants, and businesses that transform inputs— to separate what goes into the cost and what must remain as an operating expense. In our review, the most frequent error was confusing purchases of the period with the cost of the period.
This guide assumes normal operations of an SME with physical inventory, recurring purchases, and monthly or quarterly closes. It covers trading businesses, restaurants, coffee shops, and small light manufacturing businesses. More specialized cases are left out, such as industries with costing by complex processes, imports with multiple tariff layers, or valuations with high-detail specific identification that must be reviewed with the company's accountant.
We also use a key assumption: the calculation is useful if the ending inventory is well measured. If the close comes from an outdated sheet or a theoretical inventory without a count, the result loses utility. Therefore, here we prioritize procedure, accounting cutoff, and data quality over long definitions.
Component | Description | Example (coffee shop in Puebla) |
|---|---|---|
Beginning inventory | The value of all your inventory at the start of the period (month, quarter, etc.). | On January 1, you had $20,000 in coffee beans, milk, and syrups. |
Net purchases | The cost of the new merchandise you acquired in that same period, with freight and less returns and discounts. | During the month you added $50,000 in inputs. |
Ending inventory | The value of the inventory that was left unsold at the close of the period. | As of January 31, you have $18,000 left in inventory. |
Related Blogs

Oct 22, 2026
How to prevent employee petty theft in my business?

Oct 21, 2026
How to Control Food Waste in a Restaurant: 2026 Guide

Oct 20, 2026
What is the global invoice for the general public and when is it issued? SAT Guide

Oct 19, 2026
How to take restaurant orders on WhatsApp without losing any?

Oct 18, 2026
How to Create a WhatsApp Business Catalog to Sell More: 2026 Guide

Oct 17, 2026
How to set up quick replies in WhatsApp Business?
