Do a "prime factorization" of each term - that is, factor each of them down to prime numbers:
24x = 2*2*2*3*x = 8x*3
40xy = 2*2*2*5*x*y = 8x*5y
The common factors are shown in orange. The remaining (uncommon) factors are in black. Factor out the common numbers (8x):
24x-40xy = 8x*3 - 8x*5y = 8x(3 - 5y)