Ma · Mathematics

What Is the Divisibility-by-7 Rule, and Why Does It Work?

Published By the 9to5Science editorial team

At a glance

  1. 1. Split off the last digit

    Write the number as ten times the remaining part plus its last digit.

  2. 2. Double and subtract

    Subtract twice the last digit from the remaining part.

  3. 3. Repeat if useful

    Apply the same operation to the new number until the result is easy to check.

  4. 4. Use congruence laws

    Each step preserves whether the number is congruent to zero modulo seven.

A useful divisibility test for 7 is to remove the last digit, double it, and subtract that doubled digit from the part that remains. You can repeat the operation until the result is small enough to recognize. For example, the test reduces 1729 to 154 and then to 7, so 1729 is divisible by 7.

The reason the test works is that each step preserves divisibility by 7. Congruence arithmetic makes that preservation precise and also explains which arithmetic operations are safe when working modulo 7.

The divisibility-by-7 rule

Write an integer nn as

n=10q+r,n=10q+r,

where rr is its last digit and qq is the number formed by the other digits. The rule replaces nn by q−2rq-2r. Then

7∣nif and only if7∣(q−2r).7\mid n \quad\text{if and only if}\quad 7\mid(q-2r).

Here, 7∣n7\mid n means that nn is divisible by 7. The rule works for negative results too: a negative integer is divisible by 7 when it is a multiple of 7, such as −14-14.

Why the rule works modulo 7

The notation a≡b(mod7)a\equiv b\pmod 7 means that a−ba-b is divisible by 7. In particular, a number is divisible by 7 exactly when it is congruent to 0 modulo 7.

Since 10≡3(mod7)10\equiv 3\pmod 7, splitting off the last digit gives

n=10q+r≡3q+r(mod7).n=10q+r\equiv 3q+r\pmod 7.

Multiplying both sides by 5 is valid here because 5 has a multiplicative inverse modulo 7: 5⋅3≡1(mod7)5\cdot3\equiv1\pmod 7. Thus

5n≡15q+5r≡q+5r≡q−2r(mod7).5n\equiv 15q+5r\equiv q+5r\equiv q-2r\pmod 7.

The final step uses 5≡−2(mod7)5\equiv-2\pmod 7. Also, multiplying a number by 5 does not change whether it is congruent to 0 modulo 7: 5 is not divisible by 7 and has an inverse modulo 7. Therefore nn is divisible by 7 exactly when q−2rq-2r is divisible by 7.

Some versions of the test add five times the last digit instead of subtracting twice the digit. These give the same test because 5≡−2(mod7)5\equiv-2\pmod 7.

Worked example: test 1729

Apply the rule to 1729, taking care to separate the last digit at each step:

1729⟶172−2(9)=154.1729\longrightarrow 172-2(9)=154.

Now apply it to 154:

154⟶15−2(4)=7.154\longrightarrow 15-2(4)=7.

Because 7 is divisible by 7, the original number is divisible by 7 as well. In fact, 1729=7⋅2471729=7\cdot247. Each arrow preserves divisibility, so you may stop as soon as the result is a number whose divisibility you can decide.

Congruence arithmetic laws

Congruences allow you to replace numbers with simpler numbers in sums and products. If a≡b(modm)a\equiv b\pmod m and c≡d(modm)c\equiv d\pmod m, then

a+c≡b+d(modm),a+c\equiv b+d\pmod m, a−c≡b−d(modm),a-c\equiv b-d\pmod m,

and

ac≡bd(modm).ac\equiv bd\pmod m.

For example, modulo 7, 19≡519\equiv5 and 10≡310\equiv3. So 19+10≡5+3≡1(mod7)19+10\equiv5+3\equiv1\pmod 7, and 19⋅10≡5⋅3≡1(mod7)19\cdot10\equiv5\cdot3\equiv1\pmod 7. The laws follow from the definition: congruent numbers differ by multiples of the modulus, and sums and products of such expressions still give differences divisible by that modulus.

More generally, you can add or multiply congruences by the same integer. You can also substitute congruent values into any polynomial with integer coefficients. For instance, if a≡b(mod7)a\equiv b\pmod 7, then a2+3a≡b2+3b(mod7)a^2+3a\equiv b^2+3b\pmod 7.

Why division needs care

You cannot always cancel a factor in a congruence. Cancellation is valid modulo mm only when the factor is relatively prime to mm. In particular, modulo 7 you may cancel any factor not divisible by 7, because 7 is prime. For example, 2x≡2y(mod7)2x\equiv2y\pmod 7 implies x≡y(mod7)x\equiv y\pmod 7.

But modulo 8, cancellation can fail: 2⋅1≡2⋅5(mod8)2\cdot1\equiv2\cdot5\pmod 8, although 1≢5(mod8)1\not\equiv5\pmod 8. The factor 2 shares a divisor with 8, so it has no multiplicative inverse modulo 8. Similarly, dividing a congruence by 7 is not a valid operation modulo 7. When a factor is invertible, “division” in modular arithmetic means multiplying by its modular inverse.

Common mistakes

  • Subtracting the digit only once: The rule requires subtracting twice the last digit, not the digit itself.
  • Stopping at a large result: You can repeat the operation; a small result is easier to check.
  • Treating a negative result as failure: For example, −7-7 is divisible by 7.
  • Dividing or cancelling without checking: Confirm that the factor has an inverse modulo the modulus before cancelling it.

References

  1. Elementary Number Theory and Its Applications — Kenneth H. Rosen

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.