Happy Number Finder

Check if repeatedly summing squared digits leads a number to 1.

Result

Yes
4

How it is calculated

The input must be a whole number from 1 up to 9,007,199,254,740,992; a decimal, zero, a negative number or anything larger shows no result. The tool repeats one step: replace the number by the sum of the squares of its digits, n → d₁² + d₂² + …. It stops when the value reaches 1, which means the number is happy, or when a value comes up that was already seen, which means the sequence is caught in a loop and the number is not happy. The step count is the number of different values visited before stopping, including the number you typed but not the final 1, so 1 itself gives 0. It does not list the sequence, only the count. For an unhappy number the loop is always the same one: 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20.

Worked example

Test 19. Step 1: 1² + 9² = 1 + 81 = 82. Step 2: 8² + 2² = 64 + 4 = 68. Step 3: 6² + 8² = 36 + 64 = 100. Step 4: 1² + 0² + 0² = 1. The sequence reaches 1, so 19 is happy, and the tool reports 4 steps (the values 19, 82, 68 and 100). Now try 4: the values go 4, 16, 37, 58, 89, 145, 42, 20 and back to 4 without ever touching 1, so it is not happy, and the count shown is 8.

Try this example →

Common mistakes

  • Expecting the tool to list the sequence. It only says Yes or No and how many values it visited, so you must do the squaring by hand to see the path.
  • Entering 0 or a negative number. Only numbers from 1 upwards are accepted and there is no result otherwise.
  • Entering a decimal such as 2.6 and expecting it to be rounded. Only whole numbers are accepted, so no result appears.
  • Reading the step count as the number of digits or the number of squarings of the last number. It counts the values visited, so 100 gives 1 step (100 → 1) and 1 gives 0.
  • Treating a large step count as a sign of happiness. A large count can also be a long trip around the loop: 3 gives 13 steps and is not happy.

About this calculator

A happy number is a positive integer that eventually reaches 1 when you repeatedly replace it with the sum of the squares of its digits. For example, 19 is happy: 1² + 9² = 82, 8² + 2² = 68, 6² + 8² = 100, 1² + 0² + 0² = 1. Numbers that never reach 1 fall into a fixed repeating loop instead (most commonly the cycle 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4) and are called "unhappy."

Happy numbers are a classic topic in recreational mathematics and a common programming-practice exercise because detecting the cycle requires either memorizing the known unhappy loop or using a cycle-detection technique like Floyd's algorithm (the same "tortoise and hare" method used to detect loops in linked lists). They show up in coding-interview prep and math-education contexts far more than in any applied field, which is part of their appeal — a simple rule with a surprisingly structured pattern underneath.

This calculator repeats the digit-square-sum process on any positive whole number you enter until it lands on 1 (happy) or falls into the repeating loop (not happy), and tells you whether the number is happy along with how many steps the process took.

Was this helpful?

You can pick up to 3 reactions.

Comments (0)

  • Be the first to comment.

Popular calculators

All Calculators