The question you opened
All but nine of the sheep
A farmer keeps 17 sheep. All but 9 of them wander off.
How many sheep does the farmer still have?
Nine
All but nine means nine stayed behind. The answer is already sitting in the sentence, and the 17 only sets the scene.
A farmer keeps 17 sheep and all but 9 wander off. Nine sheep remain. The 17 is scenery. The trap here lives entirely in a piece of English. All but nine means every one except nine, so nine are the exception, and the exception is the group that stayed. Once you read the phrase that way, no arithmetic is needed at all. The answer of eight comes from seeing two numbers and reaching for subtraction.
It is an honest reflex. School word problems train it: numbers appear, an operation is chosen, an answer arrives. Here the reflex produces the count of sheep that left, which is a real quantity, just not the one that was asked for. There is a good habit hiding in this question. Before touching the numbers, restate the sentence in your own words and check what is being counted. Say it out loud: nine stayed, so nine are left.
If that restatement is easy, the arithmetic is often unnecessary. The same construction appears in places where getting it wrong costs money. All but the first payment is refundable. All but two of the items shipped. Everyone except three passed. Each of these names a small group and describes the rest by exclusion, and each invites the same subtraction reflex. A related version swaps the trick around: a farmer has 17 sheep and 9 wander off, so 8 remain.
Read quickly, the two versions look identical. They differ by two words, and the two words carry the whole answer. Slowing down for one beat on phrases like all but, everyone except, and none of which is cheap insurance. It is the same skill that catches a contract clause or a badly worded refund policy. The numbers in this question were never difficult. Reading was the task, and the numbers were there to pull attention away from it.
Technique: Read the phrase before the numbers