The RSI indicator formula is RSI = 100 - 100 / (1 + RS), where RS is the average gain divided by the average loss over the last 14 closes. That is the whole idea. The only tricky part is how the two averages are kept up to date, and that is what changes the number on your screen from bar to bar.
Below you will find the formula in plain steps, a complete example with 15 closing prices and every subtraction shown, the next two bars of smoothing, and a calculator above that repeats the work for any prices you paste in.
Quick read
Formula
RSI = 100 - 100 / (1 + RS)RS
Average gain / average loss over n barsDefault n
14 bars, so 15 closes for the first valueFirst averages
Plain averages of the first 14 gains and 14 lossesAfter that
(previous x 13 + current) / 14Example result
73.21 on bar 15 of our worked set
The RSI indicator formula in four lines
Gain = change if positive, else 0. Loss = minus the change if negative, else 0
RS = average gain / average loss
RSI = 100 - 100 / (1 + RS)
Losses are written as positive numbers. A drop of 0.25 is a loss of 0.25, not -0.25. If you leave the minus sign in, RS turns negative and the result is nonsense.
The first average gain is simply the sum of the first 14 gains divided by 14, and the same for losses. From the next bar on, both averages roll forward with a smoothing rule instead of a fresh 14 bar window:
New average loss = (previous average loss x 13 + today's loss) / 14
This is the same math as the smoothed moving average, an EMA with a weight of 1/14 on the newest value. It is why RSI moves calmly and why an old price spike fades slowly instead of dropping out of the window all at once.
How to use the RSI calculator above
Enter your closes in the box, one on each line or with commas between them, set the length (leave it at 14 to match the default), and press calculate. The table shows the change, gain, loss, both averages and RSI for every bar, and the working for the last bar is printed underneath so you can follow each number.
Try it with the 15 closes from the table below plus two more, 62.20 and 62.75. The calculator should print 73.21 on bar 15, 67.98 on bar 16 and 71.05 on bar 17. If you get other numbers, check that no close was typed twice and that the length is 14. The load example button fills in 20 sample closes if you only want to see how the output looks.
Worked example: RSI from 15 closing prices
Here are 15 made-up daily closes of a stock-like market. Each row subtracts the close before it, then sorts the change into the gain column or the loss column.
| Bar | Close | Change | Gain | Loss |
|---|---|---|---|---|
| 1 | 60.00 | |||
| 2 | 60.40 | +0.40 | 0.40 | 0.00 |
| 3 | 60.15 | -0.25 | 0.00 | 0.25 |
| 4 | 60.80 | +0.65 | 0.65 | 0.00 |
| 5 | 61.20 | +0.40 | 0.40 | 0.00 |
| 6 | 60.90 | -0.30 | 0.00 | 0.30 |
| 7 | 61.35 | +0.45 | 0.45 | 0.00 |
| 8 | 61.60 | +0.25 | 0.25 | 0.00 |
| 9 | 61.10 | -0.50 | 0.00 | 0.50 |
| 10 | 61.75 | +0.65 | 0.65 | 0.00 |
| 11 | 62.05 | +0.30 | 0.30 | 0.00 |
| 12 | 61.80 | -0.25 | 0.00 | 0.25 |
| 13 | 62.30 | +0.50 | 0.50 | 0.00 |
| 14 | 62.10 | -0.20 | 0.00 | 0.20 |
| 15 | 62.60 | +0.50 | 0.50 | 0.00 |
| Total | 4.10 | 1.50 |
- Average gain = 4.10 / 14 = 0.29286
- Average loss = 1.50 / 14 = 0.10714
- RS = 0.29286 / 0.10714 = 2.7333
- RSI = 100 - 100 / (1 + 2.7333) = 100 - 26.79 = 73.21
Nine of the 14 changes were up, and they were larger on average than the five down moves, so RSI lands above 70. We checked every figure in this example against an independent script that follows the same rules.

Bars 16 and 17: the smoothing step in numbers
Bar 16 closes at 62.20, a fall of 0.40. So today's gain is 0 and today's loss is 0.40.
Average loss = (0.10714 x 13 + 0.40) / 14 = 0.12806
RS = 2.1235, RSI = 100 - 100 / 3.1235 = 67.98
Bar 17 closes at 62.75, a rise of 0.55:
Average loss = (0.12806 x 13 + 0) / 14 = 0.11891
RS = 2.4539, RSI = 71.05
Notice what did not happen on bar 16. The oldest change in the window (the +0.40 on bar 2) was not dropped. In this method nothing is ever dropped; old moves just shrink in weight by 13/14 each bar. One sharp day therefore keeps nudging the reading for weeks.
Why your charting app may show a different RSI
Because each average builds on the one before it, the RSI value depends on where the calculation started. Your charting app may begin from the first bar it has loaded, which can be hundreds of bars back. A hand calculation that starts 15 closes ago will not match at first.
We tested this on a made-up series of 250 bars. RSI 14 started on bar 1 and RSI 14 started on bar 51 differed by 4.32 points on bar 71, by 0.44 on bar 101 and by only 0.01 on bar 151. The gap closes, but it takes around 100 bars to become too small to see.
| Bar | Started on bar 1 | Started on bar 51 | Gap |
|---|---|---|---|
| 71 | 53.04 | 57.36 | 4.32 |
| 81 | 45.54 | 47.60 | 2.07 |
| 101 | 57.28 | 57.72 | 0.44 |
| 151 | 52.30 | 52.31 | 0.01 |
A second source of mismatch: some versions replace the smoothing with plain 14 bar averages of gains and losses. On our bar 16 that version gives 66.07 instead of 67.98. Neither is wrong, but they are different indicators wearing the same name, so compare like with like.
From RS to RSI: what the number means
RSI is just RS squeezed onto a scale of 0 to 100. Equal average gains and losses (RS = 1) give exactly 50. The table shows how fast the scale bends near its ends.
| RS (gain / loss) | RSI | In words |
|---|---|---|
| 0.25 | 20.0 | Average loss is four times the average gain |
| 0.43 | 30.0 | The classic oversold line |
| 1.00 | 50.0 | Gains and losses balance |
| 2.33 | 70.0 | The classic overbought line |
| 4.00 | 80.0 | Gains four times the losses |
| 9.00 | 90.0 | Almost one way traffic |
To reach 70, average gains must be about 2.33 times the average losses. To get from 80 to 90, RS has to more than double again. That is why readings above 90 or below 10 are rare on a 14 bar setting. How traders act on 70 and 30 is covered on the RSI buy and sell signals page, and other lengths on RSI settings.
Where the arithmetic misleads
The formula only looks at closes. A bar that spikes far up and closes flat adds nothing to the gains. Gaps count fully, so one gap can lift RSI by many points. And the reading says how one sided recent closes were, not whether price is cheap or expensive. In our example RSI was 73.21 after a steady climb, yet nothing in the math says the climb must stop there.
Borrowed money magnifies every miss: a leveraged position can cost more than you planned, and the majority of retail accounts trading forex or CFDs on margin end up behind. Rehearse on a demo account or old charts before anything else. Everything here is general education, not financial advice; the technical analysis glossary at Investor.gov covers the wider method. For the bigger picture of the tool, start at the RSI indicator guide.
Questions traders ask
How do you calculate RSI by hand?
List 15 closes, write down the 14 changes, and split them into gains and losses with losses as positive numbers. Average each column over 14, divide gains by losses to get RS, then compute 100 - 100 / (1 + RS). After that, update both averages with the smoothing rule each new bar.
Why does RSI use 14 periods?
Fourteen is the long standing default that most charting apps load. It is a convention, not a law. Shorter lengths react faster and reach 70 and 30 more often; longer lengths move more slowly.
Can RSI reach 100 or 0?
Only if every change in the averages is a gain (RSI 100) or every change is a loss (RSI 0). With smoothing, one losing bar is enough to pull RSI below 100, so exact extremes are rare outside very short lengths.
What happens if the average loss is zero?
RS would mean dividing by zero, so calculators set RSI to 100 in that case. Our calculator above does the same.
Is RSI the same as comparing a stock with an index?
No. That comparison is often called relative strength too, but it divides one market by another. RSI looks at a single market and compares its own up closes with its own down closes.
