40871 ÷ 9 = 4541 R2
Let's divide 40871 by 9.

Step 1:
9 goes into 4 0 times with a remainder of 4.
Write down 0 as next digit of of the result. 
Result so far: 0
Subtract 0 from 4 to get 4.
Bring next digit (0) of the dividend behind the 4 and repeat the process: 40 / 9

Step 2:
9 goes into 40 4 times with a remainder of 4.
Write down 4 as next digit of of the result. 
Result so far: 4
Subtract 36 from 40 to get 4.
Bring next digit (8) of the dividend behind the 4 and repeat the process: 48 / 9

Step 3:
9 goes into 48 5 times with a remainder of 3.
Write down 5 as next digit of of the result. 
Result so far: 45
Subtract 45 from 48 to get 3.
Bring next digit (7) of the dividend behind the 3 and repeat the process: 37 / 9

Step 4:
9 goes into 37 4 times with a remainder of 1.
Write down 4 as next digit of of the result. 
Result so far: 454
Subtract 36 from 37 to get 1.
Bring next digit (1) of the dividend behind the 1 and repeat the process: 11 / 9

Step 5:
9 goes into 11 1 times with a remainder of 2.
Write down 1 as next digit of of the result. 
Result so far: 4541
Subtract 9 from 11 to get 2.

The final result is 4541 with a remainder of 2.