Why do divisibility rules work, and how do I make new ones?

I’m comfortable using a bunch of quick tests (sum of digits for 3 and 9, alternating sum for 11, the double-and-subtract trick for 7), but I don’t really understand why they work. They feel like unrelated tricks. I’m trying to see the common idea I’m missing.

For example, I know the “sum of digits” rule tells me about 3 and 9 (e.g., 123456), and the alternating-sum rule tells me about 11 (e.g., 121). For 7, I’ve seen the rule where you double the last digit and subtract from the rest, and repeat if needed, but I’m never sure I’m applying it consistently. Why do those particular digit operations reveal divisibility, and why are the patterns different for 3/9 compared to 11 or 7? I suspect it has something to do with how powers of 10 behave, but I can’t connect that idea to the specific rules.

What’s the general principle that explains these tests and lets you derive a rule for a given number (say 13 or 37) without memorizing a separate trick every time? If there is a general method, could someone outline it in a short, practical way?

Follow-up: do these rules depend on base 10? If I wrote numbers in base 8 or base 12, would a “sum of digits” style test still work for certain divisors, and how would I tell which ones? Also, is there any genuinely simple test for 7 that doesn’t involve repeating steps, or is the iterative approach basically unavoidable?

3 Responses

  1. The common thread is modular arithmetic on the base. Write your number N in base 10 as N = d0 + 10 d1 + 10^2 d2 + … and then reduce powers of 10 modulo the divisor m. If 10 ≡ 1 (mod m), then 10^k ≡ 1 for all k and N ≡ d0 + d1 + d2 + …, which explains the digit-sum test for m dividing 9 (so 3 and 9). If 10 ≡ −1 (mod m), then 10^k alternates in sign and N ≡ d0 − d1 + d2 − …, which is the alternating-sum test for m dividing 11. For 7, one convenient step is to choose t with 10t ≡ 1 (mod 7); here t = 5 because 50 ≡ 1. Writing N = 10q + d, we get 5N ≡ q + 5d ≡ q − 2d (mod 7). So N is divisible by 7 iff q − 2d is, which is the “double the last digit and subtract” rule. This is the same base-10 idea, just with a different congruence. A short background on this viewpoint: Khan Academy’s modular arithmetic overview, and a concise list of general divisibility tests on Wikipedia.

    There’s a practical recipe. Given m and base b: either find k with b^k ≡ 1 or −1 (mod m), which yields a single-step test on k-digit blocks (sum for +1, alternating sum for −1); or find t with tb ≡ ±1 (mod m), which yields an iterative last-digit rule N = bq + d ⇒ test q ± t d. Examples in base 10: for 13, 40 ≡ 1 (mod 13), so N is divisible by 13 iff “rest + 4 × last digit” is; for 37, 10^3 = 1000 ≡ 1 (mod 37), so sum the 3‑digit blocks (e.g., 5,123,456 → 5 + 123 + 456) and test that. For 7, there is also a non-iterative rule since 10^3 ≡ −1 (mod 7): write N in 3‑digit blocks from the right and take an alternating sum of those blocks; N is divisible by 7 iff that alternating sum is divisible by 7. Base dependence is the same story with 10 replaced by b. In base 8, digit-sum works for divisors of 7 (since 8 ≡ 1 mod 7), and alternating-sum works for divisors of 9 (so 3 and 9). In base 12, digit-sum works for 11, and alternating-sum works for 13.

    Is there a specific divisor you’d like to derive a rule for next, or a base you’re curious about trying this in first? Links: Khan Academy on modular arithmetic: https://www.khanacademy.org/computing/computer-science/cryptography/modarithmetic/a/modular-arithmetic, and an overview with general tests: https://en.wikipedia.org/wiki/Divisibility_rule#General_tests.

  2. The unifying idea is modular arithmetic with powers of the base: write N = Σ d_k·10^k and replace 10 by r ≡ 10 (mod n), so N ≡ Σ d_k·r^k; if r = 1 (n | 9) you get the sum of digits (3, 9), if r = −1 (n | 11) you get the alternating sum (11), and in any base B the same holds with B in place of 10 (divisors of B−1 and B+1 give the simplest tests, otherwise the digit-weights repeat with period ord_n(B)).

    For 7, use that 10·(−2) ≡ 1 (mod 7): write N = 10a + b, then N ≡ 0 ⇔ a − 2b ≡ 0, so iterate (example: 203 → 20 − 2·3 = 14 → divisible by 7); a one-shot mental test isn’t comparably simple because the fixed weights cycle with length 6.

  3. You’re exactly on the right scent: it’s all about how powers of 10 behave modulo the number you’re testing. The “digit tricks” are just different ways of exploiting the same idea: write your number in base 10, then replace each 10^k by whatever it’s congruent to mod m. Once I stopped memorizing tricks and started thinking “what does 10 look like mod m?”, all the rules suddenly lived in the same neighborhood.

    The backbone idea
    – Any number n with decimal digits d0, d1, d2, … (from right to left) is n = d0·10^0 + d1·10^1 + d2·10^2 + …
    – Work modulo m. If you know what 10 is congruent to mod m, you know what every 10^k is congruent to (just powers of that residue).
    – Then n mod m is just a weighted sum of the digits, where the weights are 1, 10, 10^2, … reduced mod m.

    Why 3 and 9 use digit sums
    – For m = 3 or 9, 10 ≡ 1 (mod m). So 10^k ≡ 1^k ≡ 1.
    – That means n ≡ d0 + d1 + d2 + … (mod m). That’s the “sum of digits” rule.

    Why 11 uses alternating sums
    – For m = 11, 10 ≡ −1 (mod 11). So 10^k ≡ (−1)^k.
    – That makes n ≡ d0 − d1 + d2 − d3 + … (mod 11). That’s the alternating sum.

    Where the 7-rule “double-and-subtract” comes from
    – Start with n = 10x + y (x is “the rest,” y is the last digit).
    – We want n ≡ 0 (mod 7). Since 10 ≡ 3 (mod 7), that’s 3x + y ≡ 0.
    – Multiply both sides by 5, which is the inverse of 3 mod 7 (because 3·5 ≡ 1). You get x + 5y ≡ 0, i.e., x − 2y ≡ 0 (since 5 ≡ −2 mod 7).
    – That’s precisely “subtract twice the last digit from the rest.” Repeat until you land on something small.

    Three general-purpose ways to build a test for any m (in base 10)
    1) The inverse method (an iterative last-digit rule)
    – Use this when gcd(m, 10) = 1 (so 10 has a modular inverse).
    – Find k with 10k ≡ 1 (mod m).
    – For n = 10x + y, n ≡ 0 (mod m) iff x + k·y ≡ 0 (mod m). This gives a quick “lop off last digit and adjust” rule.
    – Examples:
    – m = 7: 10^{-1} ≡ 5 → x + 5y, i.e., x − 2y.
    – m = 13: 10^{-1} ≡ 4 → x + 4y. So 1235 is divisible by 13 iff 123 + 4·5 = 143 is; then 14 + 4·3 = 26 is; then 2 + 4·6 = 26 is; and 26 is clearly divisible by 13.

    2) The weighted-digit sum (a one-pass test using a repeating pattern)
    – Compute the sequence of weights w0 = 1, w1 = 10 mod m, w2 = 10^2 mod m, etc. Then n is divisible by m iff d0·w0 + d1·w1 + d2·w2 + … is divisible by m.
    – Example for 7: 10 mod 7 cycles as 1, 3, 2, 6, 4, 5, … (right to left). So multiply the units digit by 1, the tens by 3, the hundreds by 2, the thousands by 6, the next by 4, the next by 5, then repeat the pattern, and sum. If that sum is divisible by 7, so is the original number.
    – This turns “repeat the step” into a single computation, which some people prefer.

    3) The block method (grouping digits when a power of 10 collapses)
    – If 10^k ≡ 1 (mod m), you can group digits into k-digit chunks and just sum those chunks.
    – If 10^k ≡ −1 (mod m), take an alternating sum of k-digit chunks.
    – Examples:
    – m = 37: 10^3 = 1000 ≡ 1 (mod 37). So 37 divides a number iff the sum of its 3-digit blocks is divisible by 37. For instance, 12,345,678 → 12 + 345 + 678 = 1035; then 1 + 35 = 36; then 36 is not divisible by 37, so the original number isn’t either.
    – m = 7 or 13: 10^3 ≡ −1 (mod 7) and 10^3 ≡ −1 (mod 13) because 1001 is divisible by both 7 and 13. So do an alternating sum of 3‑digit blocks. For 13, 1,234,567 → 1 − 234 + 567 = 334; 334 − 13·25 = 334 − 325 = 9, not divisible by 13.

    What if m shares factors with 10 (i.e., m has 2’s or 5’s)?
    – Peel those off first. Powers of 2 and 5 are handled by checking the last few digits:
    – 2^a divides n iff the last a digits form a number divisible by 2^a (in practice: last digit even for 2; last two digits divisible by 4; last three by 8; etc.).
    – 5^b divides n iff the last b digits end in enough zeros or 5/0 patterns accordingly (e.g., last digit 0 or 5 for 5; last two digits 00, 25, 50, 75 for 25; etc.).
    – For the part of m that’s coprime to 10, use one of the three methods above. Combine the results (Chinese remainder thinking) if you want the full test for m.

    How to make a rule for 13 or 37 (practical version)
    – For 13:
    – Inverse method: 10^{-1} ≡ 4 → “add 4 times the last digit to the rest” and repeat.
    – Block method: 10^3 ≡ −1 → alternate-sum of 3-digit blocks.
    – Weighted sum: powers of 10 mod 13 give weights 1, −3, 9, −1, 3, −9, and so on (from right to left). Multiply digits by these and sum.
    – For 37:
    – Block method: 10^3 ≡ 1 → sum 3-digit blocks once. Super convenient.

    Base dependence (your follow-up)
    – Everything depends on the base b you write numbers in.
    – Sum of digits works for divisors of b − 1, because b ≡ 1 (mod b − 1). In base 10, that explains 9 and 3. In base 8, sum of digits tests divisibility by 7. In base 12, sum of digits tests divisibility by 11.
    – Alternating sum of digits works for divisors of b + 1, because b ≡ −1 (mod b + 1). In base 10 that’s 11; in base 12, that’s 13.
    – More generally: if b^k ≡ 1 (mod m), use a k-digit block sum; if b^k ≡ −1 (mod m), use an alternating k-digit block sum. And if gcd(b, m) = 1, you can always do the “inverse method” with the last digit.

    Is there a genuinely simple, non-iterative test for 7?
    – Two nice one-pass options:
    – Alternating 3-digit blocks, because 10^3 ≡ −1 (mod 7). For example, 5,123,476 → 5 − 123 + 476 = 358; then 358 − 7·51 = 1, not divisible.
    – The repeating weights 1, 3, 2, 6, 4, 5 (from right to left). Multiply digits by these and sum once.
    – There isn’t a “sum of digits” style in base 10 for 7 (no b ≡ ±1), so the iterative or weighted/block approaches are the best you can do without memorizing a long pattern.

    Quick recipe you can use every time
    1) Factor m = 2^a 5^b t with gcd(t, 10) = 1.
    2) Check the last a or b digits for the 2’s and 5’s part (if any).
    3) For the remaining t, pick a style:
    – Inverse method: find k with 10k ≡ 1 (mod t), then replace 10x + y by x + k·y and repeat.
    – Weighted digits: precompute 1, 10, 10^2, … mod t and do one weighted sum.
    – Block method: find k with 10^k ≡ ±1 (mod t), then do a sum or alternating sum of k‑digit blocks.

    I used to mix up “subtract twice” with “subtract and then double” and wonder why everything broke, so if you’re ever unsure, just check a tiny example numerically-nothing like a quick sanity check to save a headache.

    I’m curious: which style feels most natural to you-the quick iterative last-digit move, the one-pass weighted sum, or the block-chunking trick?

Leave a Reply

Your email address will not be published. Required fields are marked *

Join Our Community

Ready to make maths more enjoyable, accessible, and fun? Join a friendly community where you can explore puzzles, ask questions, track your progress, and learn at your own pace.

By becoming a member, you unlock:

  • Access to all community puzzles
  • The Forum for asking and answering questions
  • Your personal dashboard with points & achievements
  • A supportive space built for every level of learner
  • New features and updates as the Hub grows