Clear guide on how the cost of goods sold is determined: formula, 4 steps, and an example with beginning inventory, net purchases, and ending inventory.
A practical guide to understanding how the cost of goods sold is determined in a Mexican SMB, featuring a visible formula, accounting steps, and applicable examples.
The cost of goods sold is not a "for later" accounting data point. It is the bridge between what you buy, what you actually sell, and the gross margin you keep. If the calculation is incorrect, prices may seem profitable when they are not.
How do we evaluate this process of determining the cost of goods sold?
To review this topic, we start from the most common accounting criterion in inventory-based businesses: recognizing the value of actually sold merchandise 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 SMBs—retail, restaurants, and businesses that transform raw materials—to separate what does go into the cost from what must remain as an operating expense. In our review, the most common error was confusing purchases of the period with the cost of the period.
This guide assumes the normal operations of an SMB with physical inventory, recurring purchases, and monthly or quarterly closings. It covers distributors, restaurants, coffee shops, and small light manufacturing businesses. It excludes more specialized cases such as industries with complex process costing, imports with multiple tariff layers, or valuations with highly detailed specific identification, which should be reviewed with the company's accountant.
We also use a key assumption: the calculation is useful if the ending inventory is accurately measured. If the closing is based on an outdated spreadsheet or a theoretical inventory without a physical count, the result loses its utility. Therefore, we prioritize procedure, accounting cutoff, and data quality over lengthy definitions here.
How is the cost of goods sold calculated? Formula and step-by-step example
The short answer is this:
Cost of goods sold = beginning inventory + net purchases − ending inventory
If you want to calculate it at the end of a month, quarter, or year, the practical sequence is as follows:
Take the beginning inventory of the period with which you opened the month or 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 shrink and write-offs.
Subtract the ending inventory to obtain the cost of goods sold for the period.
Quick example:
Beginning inventory: $30,000
Purchases of the month: $45,000
Direct freight: $2,000
Supplier returns: $1,500
Purchase discounts: $500
Ending inventory: $28,000
First, you calculate net purchases:
$45,000 + $2,000 − $1,500 − $500 = $45,000
Then, you apply the formula:
$30,000 + $45,000 − $28,000 = $47,000
That $47,000 is the cost of goods sold for the period. In accounting terms, when merchandise is sold, its carrying 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 SMB?
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 for that month, but rather the portion of inventory that actually left to generate revenue.
Base formula: beginning inventory + net purchases − ending inventory.
To calculate it at the end of a period, follow this minimum sequence:
Identify the beginning inventory with which the period opened.
Add the net purchases from the same period.
Value the ending inventory that remained unsold or unconsumed.
Subtract that ending inventory to get the cost of goods sold.
In retail 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 raw materials, such as restaurants, bakeries, and light production workshops, direct production costs also come into play, such as direct labor and, in some cases, indirect manufacturing overhead that must be allocated using 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 impacts the gross margin. If the cost of goods sold goes up and prices do not adjust, gross profit is squeezed. 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 helpful to understand what goes into and what stays out of each component so that the calculation is replicable in a spreadsheet or in your monthly closing.
1. Beginning inventory
This is the value of the inventory available at the start of the period. It must come from the previous closing 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 utility 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 raw materials
freight and hauling to put the merchandise in the warehouse or store
expenses directly attributable to acquiring inventory
Excludes:
sales expenses to the final customer
marketing campaigns
local rent
administrative salaries
interest or financial expenses
3. Ending inventory
This is the value of what remains at closing and has not yet been sold or consumed. Ideally, it is determined with a physical count and reconciliation against the system. In our review, the most costly discrepancy appeared when the business used theoretical inventory without validating actual shrink.
Sequential calculation with example
Suppose a monthly closing of a coffee shop:
Beginning inventory: $20,000
Purchases of the month: $50,000
Acquisition freight: $3,000
Supplier returns: $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 of the month is $52,000.
If that same coffee shop sold $160,000 in food and drinks, it can now compare how much of the revenue went to direct cost and how much remained as gross margin. In food businesses, this analysis is usually also followed as a percentage of sales; a practical summary of that logic appears in this explanation on food cost percentage.
Capture errors that alter the result
Using theoretical inventory instead of a physical count when there is shrink, expiration, or theft.
Excluding shrink 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 that is indeed part of the acquisition cost.
Changing the valuation method inconsistently, which makes closings incomparable.
The fundamental difference: cost of goods sold vs. cost of purchases
This is where many SMBs get confused, and the distinction does matter for the financial health of the business.
The cost of purchases is simply the money you paid out to acquire new inventory. On the other hand, the cost of goods sold focuses only on the value of inventory that was actually sold or consumed in the period. If you want to go deeper, understanding how cost of purchases is calculated is essential for accurate inventory management helps organize stock control better.
Imagine you bought $50,000 in merchandise for your barber shop in Monterrey. If at the end of the month you only used half of it in services, 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 earn less than you actually do, 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 actually profitable? If the sale price barely covers the cost, you are not building a sustainable business. The cost of goods sold is the foundation for setting healthy margins.
Which products actually leave me 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 spikes without apparent reason can be a sign of shrink, waste, theft, or a poor purchasing strategy.
In practice, ignoring the cost of goods sold is operating without a compass. You may see cash movement, but not know if the business is moving toward profitability or just spinning on misleading 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, consequently, 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 inventories under IFRS allow, among others, specific identification, FIFO, and weighted average cost, as summarized by this Wiley excerpt on inventory valuation.
Method | How it allocates costs | When it is suitable | Effect on inflation | Practical/fiscal treatment in Mexico |
|---|---|---|---|---|
FIFO | Allocates the oldest costs of inventory 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 using 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. | SMBs with many recurring purchases of homogeneous products and little need to track batch by batch. | Smooths price variations; normally leaves an intermediate result between FIFO and more recent costs. | Very useful for administrative control and stable closings. Requires discipline to recalculate the average correctly. |
LIFO | 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 fiscal practice, it is usually not the recommended operational reference for SMBs; it is best to validate it with an accountant before using it for formal reports. |
In a Mexican SMB that buys merchandise recurrently —for example, a store, coffee shop, or small pharmacy— our editorial recommendation usually leans toward FIFO or weighted average, not out of trend but for control. FIFO pairs well with perishable inventories and operations where the age of the stock matters; weighted average simplifies closings when the catalog is wide 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 calculation of the cost of goods sold does not change criteria every month.
Applying any of these methods correctly requires a very orderly system. Good inventory control is the basis for accurate valuation. If you want to dive deeper into logging best practices, it's worth reviewing more about inventory logging in our article.
Theory helps, but the real test for understanding how the cost of goods sold is determined occurs in daily operations. Let's put abstract concepts aside for a moment and perform the calculation in two scenarios that any Mexican SMB will recognize immediately.
These examples clearly show how the classic formula —beginning inventory + purchases − ending inventory— becomes a practical tool in business operations.
Case study 1: A taco shop in Mexico City
Let's take "El Sazón Chilango," a taco shop in La Roma that wants to review if its al pastor taco line actually yields the expected margin. This example works well because it allows moving from the unit cost to the cost of the period and then to the gross profit, which is where the data starts being useful for decision-making.
1. Unit cost of the taco
Al pastor meat (100 g): $5.00
Corn tortilla: $0.50
Pineapple, onion, and cilantro: $0.75
Prorated salsas 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 workday producing al pastor tacos, $4,000 is attributed to that line. If 10,000 tacos were prepared during May, 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 of the period
Now we move from the unit cost to the monthly closing:
Beginning inventory on May 1st: $8,000 in meat, tortillas, salsas, and other direct inputs.
Purchases of the month: $25,800
Supplier returns: $300
Net purchases: $25,500
Ending inventory on May 31st: $6,500 based on 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
May cost of goods sold: $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 rises due to shrink, 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 closing.
Where does each data point come from?
The beginning and ending inventory must come from the physical count of supplies.
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 switch industries and take 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 Yucatán. The cost per piece is $300, so the base cost of the batch is $15,000.
Shipping cost (freight): transporting the batch from Yucatán 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 of blouses + $1,000 of freight = $16,000.
Unit cost: $16,000 / 50 blouses = $320 per blouse. That is the actual cost per garment placed in the store.
With that correct unit cost, the boutique can now calculate its quarterly cost of goods sold.
Beginning inventory (January 1st): 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 31st): 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 plan its next purchases better.
The impact of new consumer 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.
Common errors 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 to making strategic decisions with incorrect information.
In our review, we detected recurring pitfalls in commercial and retail SMBs. The good news is that identifying them is the first step to correcting them and protecting the margin.
Mixing operating expenses with the cost of goods sold
This is, without a doubt, the most classic error. It is easy to throw the local rent, the manager's salary, social media ads, and the cost of merchandise into 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 sold unit.
The correction is simple, although it requires discipline: separate accounting ledger accounts.
In cost of goods sold, the following should appear: raw materials, direct labor, freight to bring merchandise to the warehouse, and directly attributable import costs.
In operating expenses goes everything else: administration, sales, rent, utilities, advertising, among others.
Think of it this way: in a barber shop in Monterrey, wax, blades, and a portion of the barber's salary associated with the service can be linked to the direct cost. The Instagram campaign to attract customers and the local rent cannot.
Ignoring shrink 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, ending inventory appears higher than actual, which artificially lowers the cost of goods sold and elevates a gross profit that does not exist in the cash register.
Shrink 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: "shrink by expiration," "damaged product," "internal theft."
Record their value: when you write off a product, its cost must impact the corresponding period.
Leverage 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 be your best ally in our article.
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 the machinery used to produce.
Imagine a small artisan ice cream shop in Puebla that invested $150,000 MXN in an ice cream maker. If its estimated useful life is 5 years, it loses $30,000 in value each year.
That cost, even if it does not involve a monthly cash outflow, does represent a real production cost. It must be distributed among the liters or units manufactured and sold.
The practical solution here is to review the topic 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, capture errors, and little clarity on how much you actually earn.
This is where technology becomes an ally. An end-to-end platform like Swirvle doesn't just record sales; it helps organize the operation 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 record a sale, the system updates information relevant to inventory and cost.

Sale made, inventory updated. If you sell a garment or a medicine, 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 across periods.
Let's think of a pharmacy in Mexico City. With each sale, the system not only knows which medicine left but also which batch it came from, helping link the outflow with its corresponding purchase cost. That improves financial visibility and operational order.
Smart recipes: 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 pains. The logic of recipes helps precisely at that point.
Imagine a coffee shop in Puebla. Within the platform, you define the recipe for a "large cappuccino":
30 grams of coffee beans
200 ml of whole milk
1 cup of 12 oz
1 cup lid
If the system already knows the unit cost of each input, when recording the sale of the cappuccino, it can automatically sum the cost of those components, register it as the cost of goods sold of that drink, and deduct the precise quantities from the inventory of each input. The result is a much clearer view of the margin per product.
Allocation by branch, campaign, or even by salesperson
Knowing the total cost of goods sold is useful, but the real value appears in the details. 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 such as: 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 shrink.
Campaign evaluation: a promotion can increase sales, but also put pressure on the margin; measuring both helps to evaluate its result better.
Commercial performance: reviewing which products rotate best for each team can provide useful signals for training and sales mix.
With visual dashboards, the operation stops depending on estimates and gains traceability to make decisions with more certainty.
Answers to the most common questions about the cost of goods sold
Even if the formula seems clear on paper, daily operations always bring very specific doubts. In our review, some topics repeated over and over among SMB owners looking to better understand how the cost of goods sold is determined. Here we clarify the most important ones.
Does the freight I pay to receive merchandise count as cost of goods sold?
Yes. In fact, not including it is a common error. Those products would not be in your warehouse, shelf, or kitchen if you had not paid for their transport. 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— in front of the final customer; that already falls under commercial operations.
What do I do with shrink or inventory that went bad?
Shrink is a reality in any business with inventory. We are talking about expired, broken, transit-damaged, or even stolen product. Account-wise, it must be recorded as an inventory write-off, and its value has to impact the period in which the loss is detected.
Ignoring it is deceiving yourself. If you do not record that shrink, the ending inventory in books remains higher than actual. That makes your cost of goods sold seem lower than it is and artificially inflates your profit. An ice cream shop in Yucatán that loses several liters due to a freezer failure needs to reflect it; if it doesn't, it will think it earns more than it actually does.
Are local rent and administrative salaries included?
No, and this difference is important. Rent, the manager's or accountant's salary, marketing investment, and utilities like internet or electricity are operating expenses.
Operating expenses keep the business alive, but 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 sources of greatest 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 in criteria: your accountant might be including a direct cost that you left out, or vice versa.
Different accounting cutoffs: a few hours of difference at closing 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 stay out. 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 the cost of goods sold is calculated is only the first step. The real value appears when you use that information to make better decisions and grow with more control.
Discover how Swirvle can transform the management and growth of your business.
Component | Description | Example (Coffee Shop in Puebla) |
|---|---|---|
Beginning Inventory | The value of all your inventory at the start of the period (month, quarter, etc.). | You had $20,000 in coffee beans, milk, and syrups on January 1st. |
Net Purchases | The total cost of all new inventory you acquired during that same period. | You purchased an additional $50,000 in supplies during the month. |
Ending Inventory | The value of the inventory that remained unsold at the end of the period. | As of January 31st, you have $15,000 left in inventory. |
Related Blogs

Oct 6, 2026
Which campaigns work to fill a restaurant during the week?

Oct 5, 2026
Does Excel work as a CRM for a small business, or is it better to use a software?

Oct 4, 2026
How to organize my client information if I have a small business? Guide

Oct 3, 2026
What message should I send on WhatsApp to win back a customer who is no longer returning?

Oct 2, 2026
Grocery Store Software: 2026 Comparative Guide

Oct 1, 2026
Omnichannel CRM for Physical Businesses in 2026
Try Swirvle for free
No card required · 30 days free
Start your free trial
