Happy Number Checker
Test if a number is a happy number.
Result
How it is calculated
A happy number is one that ends at 1 when you repeat a simple step: replace the number with the sum of the squares of its digits. The tool does exactly this loop, n → Σ dᵢ², counting each step, and stops when it reaches 1 or when a value repeats, which means it is stuck in a cycle. If 1 is reached the number is called happy and the step count is shown; otherwise it is not happy and the steps show a dash. Whole numbers from 1 to 1,000,000,000 are accepted, and decimals are cut to the integer part. Every unhappy number eventually falls into the same cycle that contains 4.
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 reached 1 after 4 steps, so 19 is a happy number. By contrast, 4 goes 16, 37, 58, 89, 145, 42, 20 and back to 4, so it is not happy.
Common mistakes
- Squaring the whole number instead of each digit. For 19 you add 1² and 9², not 19².
- Forgetting zero digits. They add nothing, but they must not be skipped when you are counting the digits by hand.
- Counting the starting number as a step. The tool counts only the replacements, so 19 takes 4 steps and not 5.
- Expecting a result for 0 or negative numbers. The tool accepts positive whole numbers only, up to 1,000,000,000.
- Assuming the sequence for an unhappy number can run forever. It always lands in the same loop, so the check always ends.
About this calculator
This tool checks whether a number is a happy number: repeatedly replace the number with the sum of the squares of its digits, and if the process eventually reaches 1, the number is happy (e.g. 19 → 1²+9²=82 → 8²+2²=68 → 6²+8²=100 → 1²+0²+0²=1). Numbers that instead fall into the repeating cycle 4→16→37→58→89→145→42→20→4 are called "unhappy" or "sad."
Programmers use this classic exercise to practice loops, digit manipulation, and cycle detection in coding interviews and algorithm courses, and recreational-math enthusiasts explore happy numbers as a light introduction to number theory.
Was this helpful?
You can pick up to 3 reactions.
Popular calculators
Loan Calculator
Monthly payment, total interest and full amortization schedule.
Percentage Calculator
Percent change, percent of, and ratio calculations.
Discount Calculator
Calculate final price, savings, and discount amount.
BMI Calculator
Body mass index from height and weight (metric or imperial).
Age Calculator
Compute your exact age in years, months and days from a birth date.
Compound Interest Calculator
Calculate the final amount and interest earned with compounding.
All Calculators
- Loan Calculator
- Profit Calculator
- Discount Calculator
- BMI Calculator
- Percentage Calculator
- Ideal Weight Calculator
- Age Calculator
- Pregnancy Due Date Calculator
- Compound Interest Calculator
- BMR Calculator (Basal Metabolic Rate)
- Tip Calculator
- Fuel Cost Calculator
- Date Difference Calculator
- Sleep Cycle Calculator
- Daily Water Intake Calculator
- Simple Interest Calculator
- Heart Rate Zones Calculator
- Running Pace Calculator
- Pet Age Calculator
- Calories Burned Calculator
- Macro Calculator
- TDEE Calculator (Total Daily Energy Expenditure)
- Waist-to-Hip Ratio Calculator
- Honor Roll Calculator
- One Rep Max (1RM) Calculator
- Ovulation Calculator
- Electricity Cost Calculator
- Unit Price Calculator
- Savings Goal Calculator
- Break-Even Point Calculator
- Paint Calculator
- Course Grade Average Calculator
- Business Days Calculator
- Time Duration Calculator
- Fuel Economy Calculator
- Temperature Converter
- Tile Calculator
- Aspect Ratio Calculator
- Roman Numeral Converter
- Goal Weight Timeline Calculator
- Salary Converter (Hourly to Annual)
- Credit Card Validator (Luhn)
- Body Surface Area (BSA) Calculator
- Feels-Like Temperature Calculator
- Ohm’s Law Calculator
- PPI (Pixel Density) Calculator
- Molar Mass Calculator
- Zodiac Sign Calculator (Western + Chinese)
- IBAN Validator
- Shoe Size Converter
- Country Info & Dialing Code Lookup
- Time Zone Difference (World Clock)
- CAGR (Compound Annual Growth Rate) Calculator
- Rule of 72 Calculator
- Blood Alcohol Content (BAC) Calculator
- Lean Body Mass (LBM) Calculator
- Pythagorean Theorem Calculator
- Speed Converter
- Download Time Calculator
- Date Calculator (Add/Subtract)
No calculators found
Comments (1)
Only the digits matter, not their order or any zeros, so numbers that share the same digits share the same fate: 19, 91, 109 and 190 are all happy. Below 20 the happy ones are 1, 7, 10, 13 and 19, a handy list for checking a program you write yourself. Have you found a number below a million with a surprisingly long chain?