You've been building a position in a stock over three years — buying at different prices each time. Now you decide to sell 100 shares. The question your tax authority will ask is simple: which 100 shares did you sell?
It sounds like a trivial accounting question. But the answer can mean hundreds or even thousands of euros difference in your tax bill for the year. This is the core of the FIFO vs LIFO debate for investors.
⚠️ Important: Tax law varies by country. Many jurisdictions — including Spain and most EU countries — legally mandate FIFO for calculating capital gains on securities. Always consult a tax professional for your specific situation. This article explains the mechanics of both methods, not a recommendation of which to use.
What Is Cost Basis?
Before diving into FIFO and LIFO, you need to understand cost basis. Your cost basis is the original value of an asset for tax purposes — typically what you paid for it, including fees. When you sell an asset, your taxable gain (or loss) is:
The challenge arises when you bought the same asset multiple times at different prices. You have multiple "lots" with different cost bases, and the order in which you assign them to a sale determines your gain.
FIFO: First In, First Out
Under FIFO, the shares you bought first are considered to be the ones you sell first. This is the most common method — and the one legally required in most European countries for securities.
In a rising market, FIFO typically results in a higher taxable gain, because the oldest shares were usually purchased at the lowest price, creating the largest difference between cost basis and sale price.
LIFO: Last In, First Out
Under LIFO, the shares you bought most recently are treated as the first ones sold. In a rising market, LIFO tends to result in a lower taxable gain, because the most recent purchases usually have a higher cost basis, reducing the gain on sale.
However, LIFO is not permitted for securities in many jurisdictions, including most of the EU and the UK. It's more commonly used in inventory accounting for businesses. Individual investors in Europe should default to FIFO unless specifically advised otherwise by a tax professional familiar with their jurisdiction.
A Side-by-Side Example
Let's say you bought shares of the same ETF on three occasions:
| Date | Shares Bought | Price per Share | Total Cost |
|---|---|---|---|
| Jan 2024 | 50 | €80 | €4,000 |
| Jul 2024 | 50 | €95 | €4,750 |
| Jan 2025 | 50 | €110 | €5,500 |
| Total | €14,250 | ||
In March 2026 you sell 50 shares at €130 per share. Sale proceeds: €6,500.
| Method | Shares Identified as Sold | Cost Basis | Taxable Gain |
|---|---|---|---|
| FIFO | 50 shares from Jan 2024 (€80 each) | €4,000 | €2,500 |
| LIFO | 50 shares from Jan 2025 (€110 each) | €5,500 | €1,000 |
Same sale, same shares, but the taxable gain is €2,500 under FIFO versus €1,000 under LIFO — a difference of €1,500. At a 19% capital gains tax rate (common in Spain for gains under €6,000), that's a difference of €285 in actual tax owed, just on this one sale.
Now scale that across a portfolio of 10–20 positions, each with multiple purchase lots, sold at various points throughout the year. The cumulative effect of cost basis methodology on annual tax liability can be substantial.
The Average Cost Method
Some countries and brokers also allow a third method: Average Cost (also called weighted average). Under this approach, you calculate the average price paid across all your purchases and use that as the cost basis for all shares sold.
In the example above, your average cost per share would be €14,250 / 150 = €95. Selling 50 shares at €130 gives a gain of (€130 − €95) × 50 = €1,750 — between the FIFO and LIFO results.
Average cost is simpler to calculate but may not be available in all jurisdictions or for all asset types. In Spain, FIFO is mandatory for capital gains calculation on securities; average cost is typically used only for investment funds (participaciones).
Which Method Applies to You?
The answer depends almost entirely on where you live and what you're selling:
- Spain: FIFO is mandatory for stocks, ETFs and crypto. Investment funds use average cost (precio medio ponderado).
- UK: Section 104 pooling applies to most securities — essentially a form of average cost.
- United States: FIFO is the default, but investors can elect specific share identification or average cost for certain assets.
- Most EU countries: FIFO or average cost, varying by country and asset type.
The practical takeaway: know your jurisdiction's rules before assuming you can choose. In most cases for European investors, FIFO is what your tax authority expects you to use for securities.
Why This Matters for Your Records
Regardless of which method applies, calculating capital gains correctly requires complete, accurate records of every purchase lot: date, number of shares, price per share, and any fees paid. Many investors don't keep these records — they just know their overall return, not the breakdown by purchase date.
This creates two problems. First, they can't accurately report capital gains. Second, they often overpay — because they default to using a vague average that may not reflect the actual FIFO cost basis their jurisdiction requires.
WealthFlow maintains a complete transaction history with every purchase lot recorded. Its tax report feature applies FIFO calculation automatically across your entire portfolio for a given fiscal year, generating a CSV you can hand directly to your accountant — with each sale matched to its correct purchase lots, dates included.
Get your FIFO tax report automatically
WealthFlow Pro calculates your capital gains using FIFO across all your assets and exports a clean CSV for your accountant. No manual calculations needed.
Start for free →