Two Doors, Two Guards, One Question

One door leads out, the other does not. One guard always tells the truth, the other always lies, and you cannot tell them apart. You may ask one guard one question.
Asking which door is safe gets you nowhere, since you do not know whether to trust the reply. You need a question whose answer comes out the same whichever guard you ask.
The question
Ask either guard: If I asked the other guard which door leads out, what would he say? Then take the opposite door.
Why it works
There are two cases, and it helps to walk through each.
- You asked the truth teller. The liar would point to the wrong door, and the truth teller faithfully reports that wrong door.
- You asked the liar. The truth teller would point to the right door, and the liar misreports it as the wrong door.
Either way the answer has passed through exactly one lie, so you always hear the wrong door. Take the other one.
The wider idea
When you cannot trust a single source, you can sometimes design a question that makes the error predictable. A signal with a known bias is nearly as useful as an honest one, which is why a clock that runs exactly five minutes fast never really fooled anybody.