If you’ve been in the IT workforce for more than a few weeks, you’ve probably had one of those facepalm moments when you simply can’t believe the stupidity of some management decision. It must be a common experience, since “Dilbert” is still around after decades on the comic pages. Depending on your temperament and experience, you feel bewilderment, anger, hopelessness or apathy.

In those moments, it’s easy to dismiss your boss (or someone five steps up the ladder) as an idiot, to simply write that person off and forever assume that he doesn’t know what he is doing. But it would be a mistake to do so.

Of course, sometimes your instinct is right and it really is a bad decision, one that ignores inconvenient facts or expert advice in favor of the decision-maker’s internal beliefs. Some leaders believe themselves infallible, and some people won’t accept that they can’t get what they want until every possible approach — including the ridiculous — has failed.

But a lot of decisions that might seem downright crazy to you make more sense than you suspect. Most of the time, when you don’t understand why a decision was made, it means that you don’t really understand the decision-maker’s goals or overall mandate. If you take a step back, you might be able to make sense of the situation.

The first time I remember doing this was when a major seven-figure project I had worked on for several years was abruptly canceled. The client was a major retail chain with tens of thousands of locations around the world. My team had been hired to develop a new generation of point-of-sale registers. For years, the company had been buying expensive, out-of-date, proprietary systems from two different suppliers. If it developed its own system, it could both lower equipment costs and improve operational efficiency with more accessible sales data. So it hired us to build it for them.

From our point of view, the project had gone quite well. The software and hardware development had been smooth. We had installed test systems in numerous stores in several countries with good results. The new system met the client’s requirements — open, reliable, with lower costs and greater efficiency.

It was an exciting time. After several years of hard work, we were on the verge of success. We were gearing up to start full-scale production, distribution and support of the new hardware. Our managers were feeling great. And our clients seemed happy too.

But then one day, the client’s board of directors met with the heads of the two companies that had been supplying the chain’s existing POS systems. The following day, our entire project was canceled.

I couldn’t believe it. The company had spent years of work and tens of millions of dollars developing the new system. It made no sense to me, and I wondered what kind of idiots would do such a thing. I could see that my managers were upset too. But strangely, the project leaders from the client side didn’t seem nearly as distressed.

It slowly dawned on me that my assumptions about the client’s purpose for our project were all wrong and that the board knew exactly what it was doing. I assumed that the company wanted the technology we developed and the business benefits that it would confer. But really, it had spent tens of millions of dollars on our project as a bargaining chip in a high-stakes deal worth hundreds of millions of dollars. It needed a credible alternative with which to pressure the existing vendors to lower their prices and open and update their systems.

In the end, the retailer got exactly what it wanted. For us, it felt as if all our work had been for nothing. But for the client, it was money well spent. For it, the project was a win no matter how the negotiations turned out. It would get the benefits it wanted from the existing vendors or from the new technology, but from the start it probably preferred to stick with the outside vendors.

So when you experience your next facepalm moment, don’t write off the decision-makers as idiots until you’ve take a step back and thought carefully about what they really want.