Happy Number Calculator

Run the sum of squared digits over and over to see whether a number reaches 1 or loops forever.

Math and PercentUpdated 2026-11-183 min read
Happy Number Calculator
A whole number from 1 to 1,000,000,000,000.
Verdict
...
Steps to reach 1 or repeat...
Chain of values...

What it does

A happy number is found by a simple repeated action. Replace the number by the sum of the squares of its decimal digits, then do the same to the result, and keep going. If the chain lands on 1, the starting number is happy. If it falls into a repeating cycle that never includes 1, the number is unhappy.

Take 19 as an example. Its digits give 1 squared plus 9 squared, which is 82. The next step gives 68, then 100, then 1. Four steps is enough to settle the question. For 4 the path is 4, 16, 37, 58, 89, 145, 42, 20, and then back to 4, so it can never reach 1.

The idea has been studied at least since the early twentieth century and appears in recreational number theory. There is no closed formula that decides happiness from the size of a number alone. You have to iterate, but the process settles quickly because the digit square sum shrinks large inputs dramatically.

This page runs the iteration for you, stops when it sees 1 or a repeated value, and reports both the verdict and the full chain. It keeps a guard on the number of steps so even a hostile input cannot make the page loop without end.

Only base ten is used. The same idea can be defined in other bases, but the sequence of values would change, and this tool is deliberately limited to ordinary decimal notation.

How to use

  1. Enter a whole number n from 1 upward.
  2. Read the verdict in the main result box.
  3. Check the step count to see how long the chain ran.
  4. Read the chain from left to right to follow each squared digit sum.
  5. Use the default 19 to reproduce the worked example.
  6. Try 4 to watch a chain close into a loop.

Formula

next(n) = sum of d_i^2 for every decimal digit d_i of n
n
The current integer in the chain, starting from the input.
d_i
One decimal digit of the current number.
next(n)
The sum of the squares of those digits, used as the next value.

The map always sends a number to a much smaller one once it has more than three digits, so the chain enters a small set of values quickly. There are only two possible outcomes: the fixed point 1, or the well known eight term loop containing 4, 16, 37, 58, 89, 145, 42 and 20. The tool records values it has already seen and stops as soon as one repeats.

Worked example

Example: 19

The tool opens with n = 19 already entered.

  1. Square the digits of 19: 1^2 + 9^2 = 1 + 81 = 82.
  2. Square the digits of 82: 8^2 + 2^2 = 64 + 4 = 68.
  3. Square the digits of 68: 6^2 + 8^2 = 36 + 64 = 100.
  4. Square the digits of 100: 1^2 + 0 + 0 = 1.
  5. The chain is 19 -> 82 -> 68 -> 100 -> 1.
  6. The tool reports Happy number, four steps, and that same chain.
  7. A number already at 1 needs zero steps and is happy by definition.

Reference table

Outcomes for small starting numbers
nVerdictStepsChain
1Happy01
7Happy57 -> 49 -> 97 -> 130 -> 10 -> 1
10Happy110 -> 1
13Happy213 -> 10 -> 1
19Happy419 -> 82 -> 68 -> 100 -> 1
4Unhappy84 -> 16 -> 37 -> 58 -> 89 -> 145 -> 42 -> 20 -> 4

Limits

  • The chain is computed in base ten only.
  • Inputs above one trillion are rejected.
  • The tool stops after a fixed step guard even though most chains settle within a dozen steps.
  • It does not list every number in a loop, only the values seen before the repeat was detected.

Common mistakes

  • Adding digits instead of squaring them before adding.
  • Stopping as soon as any digit repeats rather than when a whole value repeats.
  • Assuming all numbers ending in zero are unhappy.
  • Forgetting that 1 is happy with no steps at all.
  • Carrying the iteration past 1, which would leave the fixed point.

Try it yourself

Quick checks. Answers sit tucked under each question.

Is 7 happy and in how many steps?

Yes, in 5 steps: 7 -> 49 -> 97 -> 130 -> 10 -> 1.

Is 4 happy?

No. In 8 steps it returns to 4 through 16, 37, 58, 89, 145, 42 and 20, so it is unhappy.

How many steps does 10 need?

One step, because 1^2 + 0^2 + 0^2 = 1.

Questions

What is an unhappy number?

A number whose squared digit chain never reaches 1 and instead cycles forever.

What is the loop for unhappy numbers?

In base ten the cycle is 4, 16, 37, 58, 89, 145, 42 and 20.

Are there infinitely many happy numbers?

Yes. Every power of ten is happy, and inserting zeros anywhere into a happy number keeps it happy.

Does digit order matter?

No, because the sum of squared digits is the same for any permutation of the digits.

How big can the input be?

Any whole number through 1,000,000,000,000. Large values shrink quickly under the map.

Does changing the base change the answer?

Yes, happiness is defined relative to a base. This page always uses base ten.

Sources

How this page was checked. The formula above was matched against the cited sources, and the worked example was run through the tool on this page before publishing. If you spot an error, contact us so we can fix it and note the correction.