Skip to main content

Armstrong Numbers Explained: Why 153 Equals Its Own Digit Powers

A clear guide to Armstrong numbers (narcissistic numbers): the digit-power rule, the famous three-digit set, a hand-checked example, and the classic coding interview question.

Published By Li Lei
#armstrong number #narcissistic number #number theory #coding interview #algorithms

Armstrong Numbers Explained: Why 153 Equals Its Own Digit Powers

The first time I met an Armstrong number was in a first-year programming lab, and the assignment looked deceptively small: "write a function that returns true if a number is an Armstrong number." I wrote a loop, ran it on 153, got true, felt clever, and submitted. It failed on 9474. The bug was a single wrong exponent, and I had no quick way to see where my arithmetic and my code disagreed. That gap between "my loop says no" and "but why" is exactly what this post is about.

The rule, stated precisely

An Armstrong number of d digits equals the sum of each of its digits raised to the power d. That single sentence carries the whole definition, so it is worth reading twice. The exponent is not fixed at 2 or 3. It tracks the digit count. A three-digit number cubes each digit. A four-digit number raises each digit to the fourth power. A seven-digit number raises each digit to the seventh.

Concretely: count the digits to get n, raise every digit to the nth power, add the results, and compare the total back to the original number. If the sum lands on the number you started with, it is an Armstrong number. If it overshoots or falls short, it is not.

That base-dependent exponent is the detail people miss. If you instead picked a fixed power and applied it to every input, you would be describing a different family entirely, the perfect digital invariants. Armstrong numbers insist the power always equals the length.

A worked example: 153

The textbook case is 153, and it is the cleanest way to internalize the rule. The number 153 has three digits, so n = 3 and every digit gets cubed:

1^3 + 5^3 + 3^3
= 1 + 125 + 27
= 153

The sum reproduces the original number, so 153 qualifies. Walk it slowly: 1 cubed is 1, 5 cubed is 125, 3 cubed is 27, and 1 plus 125 plus 27 is 153. Nothing hides in the middle. This is why a good checker prints each term rather than a bare yes or no, so you can see precisely which digit and which power produced the running sum. You can confirm the full breakdown yourself in the Armstrong Number Checker, which lays out every term and the comparison.

A second example settles the four-digit case, where the exponent jumps to 4. Take 9474:

9^4 + 4^4 + 7^4 + 4^4
= 6561 + 256 + 2401 + 256
= 9474

Again the digit-power sum returns the original. Notice that cubing 9474 instead of raising to the fourth would give a completely different total and a false negative. That mistake, applying the wrong exponent, is the single most common way to get this wrong by hand or in code.

The famous three-digit set

When people say "narcissistic number," they often mean the three-digit cases specifically. There are exactly four:

  • 153 = 1³ + 5³ + 3³
  • 370 = 3³ + 7³ + 0³
  • 371 = 3³ + 7³ + 1³
  • 407 = 4³ + 0³ + 7³

Two of these, 370 and 371, sit right next to each other and make a satisfying pair for an interview answer. Note also that 372 is not Armstrong: 3³ + 7³ + 2³ = 27 + 343 + 8 = 378, which is not 372. Being one away from a narcissistic number buys you nothing.

What surprises most people is the gap below 153. There are no two-digit Armstrong numbers at all. Every single digit from 0 through 9 qualifies trivially, because d to the first power is just d, and then the next entry is 153. The whole list under ten thousand is short: the single digits, then 153, 370, 371, 407, 1634, 8208, and 9474. If you scan the range from 0 to 10000 and watch how few survive, the rarity of the property stops being abstract.

The checking algorithm

The reason this problem shows up in intro courses and interview warm-ups is that it drills the exact skills a beginner needs: pulling digits out of an integer and looping with an accumulator. Here is the shape of the algorithm in plain terms.

  1. Convert the number to a string, or keep dividing by 10, to find the digit count n.
  2. Extract each digit, usually with digit = num % 10 followed by num = num // 10 (integer division).
  3. Raise each digit to the power n and add it to a running sum.
  4. After all digits are consumed, compare the sum to the original number.

A compact Python version:

def is_armstrong(num):
    digits = str(num)
    n = len(digits)
    total = sum(int(d) ** n for d in digits)
    return total == num

The trap is in step 1. You must compute n from the original number once, before you start consuming digits. If you recompute the length while you are dividing the number down, it shrinks, and your exponent collapses to nonsense. Lock the digit count in first.

A classic interview question

Armstrong numbers earn their place as an interview warm-up because they test digit manipulation without dragging in heavy algorithms or data structures. There is no graph, no sort, no clever data structure, just careful arithmetic and a clean loop. That makes them a fair way to see whether a candidate can translate a plain-English rule into correct code under mild pressure.

If you are preparing, rehearse three things. First, state the rule out loud: the exponent equals the digit count. Second, hand-trace one example, ideally a four-digit one like 8208 (8⁴ + 2⁴ + 0⁴ + 8⁴ = 4096 + 16 + 0 + 4096 = 8208), so the wrong-exponent mistake never sneaks in. Third, be ready to name the small set below 10000 from memory. When I want the pattern fresh before a session, I run a few values through the Armstrong Number Checker and read the per-term breakdown, then reproduce those exact intermediate terms in my own function. If my code prints the same partial sums, the digit loop and the exponent are both right.

For the broader number-theory side of these problems, digit-power families connect naturally to factor structure, so a tool like the prime factorization checker pairs well when you are exploring why certain numbers behave the way they do.

Wrapping up

Armstrong numbers reward a small amount of precision and punish sloppiness in one specific spot: the exponent. Get the digit count first, raise each digit to that power, sum, and compare. Memorize the four three-digit cases, remember that no two-digit case exists, and never cube a number that has four digits. Do that, and both the homework problem and the interview warm-up turn into a thirty-second exercise instead of a debugging session.


Made by Toolora · Updated 2026-06-13