If n is the number, then the sum of the digits is the remainder after dividing the number by 9 plus a multiple of 9. For example, if n=12345, division by 9 gives a remainder of 6. The digits add up to 15 which is 9+6. Note also that 1+5=6.
Another example: 65478/9 has remainder 3 while the sum of the digits is 30=3*9+3.
It's easier to use this in reverse: add the digits of a number together. If the result is more than one digit, add the digits of this result. Repeat if necessary until there is only one digit. That final digit is the remainder if the original number had been divided by 9. If the final digit result is 9 itself, then the remainder is zero, in other words, the original number is exactly divisible by 9.
The reason for this is that a three digit number, for example, can be represented by 100a+10b+c. This can be written 99a+a+9b+b+c=(a+b+c)+99a+9b=(a+b+c)+9(11a+b). Here we have the sum of the digits plus a multiple of 9. A similar argument applies to a number with as many digits as you like. The number 12=10+2=9+(1+2)=9+3, where the sum of the digits is 1+2.
12345 = 10000+2000+300+40+5 = 9999+1+2*999+2+3*99+3+4*9+4+5 = 9(1111+222+33+4)+(1+2+3+4+5) = 9*1370+1+2+3+4+5 = 9*1370+9+6=9*1371+6 (=12339+6).