Digit iterations
Happy numbers and the unhappy loop
3 min read · Updated 19 September 2026
Take a number, square each of its digits and add the squares. Repeat. If you eventually reach 1, the number is called happy. If not, it is unhappy, and something remarkable happens: every unhappy number ends up in the same eight-number loop. Like Kaprekar’s routine, this is a digit game that must settle down, and we can prove why.
Two examples
7 → 49 → 97 → 130 → 10 → 1 (happy)
4 → 16 → 37 → 58 → 89 → 145 → 42 → 20 → 4 (unhappy loop)
Starting from 7: 7² = 49, then 4² + 9² = 97, then 9² + 7² = 130, then 1 + 9 + 0 = 10, then 1. Once you reach 1 you stay there, because 1² = 1.
The happy numbers up to 50
1, 7, 10, 13, 19, 23, 28, 31, 32, 44, 49
There are 20 happy numbers between 1 and 100. Reordering digits does not change the result, because the sum of squares ignores order: 13 and 31 are both happy, and so are 19 and 91. Inserting zeroes changes nothing either, so 7, 70 and 700 are all happy.
Why every number ends at 1 or in the loop
The key observation is that large numbers shrink. A number with k digits has a digit-square sum of at most 81k. For a four-digit number that is at most 324, far smaller than the number itself. So any starting value, however large, quickly drops below 1,000.
Once below 1,000, the sum is at most 3 × 81 = 243, so the process stays inside a finite set. On a finite set a repeated rule must eventually repeat a value, and checking every number below 243 shows only two possible endings: the fixed point 1 or the loop 4 → 16 → 37 → 58 → 89 → 145 → 42 → 20.
This is exactly the finite-state reasoning that works for Kaprekar’s routine, and exactly what is missing in the Collatz conjecture.
How common are happy numbers?
Among the first thousand whole numbers, 143 are happy, and the proportion stays close to that level further on: about 14.3% of the numbers up to one million are happy. The proportion does not settle to one fixed limit, but it wanders in a fairly narrow band.
Happy numbers also come in runs. The first pair of consecutive happy numbers is 31 and 32. The first run of three begins at 1880, the first run of four at 7839 and the first run of five at 44488.
Where the name comes from
The origin of happy numbers is not certain. They are usually traced to a British school: the mathematician Reg Allenby heard of them from his daughter, who had learned them in class, and they were then popularised through Richard Guy’s collection Unsolved Problems in Number Theory. Because they are easy to test by hand, they became a favourite classroom activity.
Questions to explore
- Happy primes are numbers that are both happy and prime, such as 7, 13, 19, 23 and 31. How many can you find below 100?
- Is there a run of consecutive happy numbers? (31 and 32 are both happy.)
- Change the rule to cubes of digits. Which numbers are fixed points? (See narcissistic numbers.)
A shortcut when testing by hand: as soon as you reach any number in the loop, such as 4, 16, 20, 37, 42, 58, 89 or 145, you can stop. The number is unhappy.