Plan your escape
If you're fortunate enough to be unmasked when you're brought to your cell, you can already begin to plot your escape. It's important to realize that, even if you co-operate, your captors aren't likely to let you go with a fruit basket and a "thank you" card. Try to remember any codes or hallways you spot. Try to find flaws or patterns in the building. These may just save your life when you're making your daring escape.
Wimp out

Transcend the physical
If you're not a man of religion, then it's time to find God. Many have reported that meditation can help you overcome extreme stress and pain. Buddhist monks have managed amazing physical feats like surviving Himalayan winters or burning to death without moving an inch simply through the power of meditation. Try to take yourself to a better place and, as impossible as it may sound, leave your pain behind.

I know you pass out real quick after 4 beers at every frat party you've ever been to, but this is very different. Passing out in this situation can buy you some mercy from your captors if they believe that you are passing out from pain. Their motivation isn't to knock you out with pain, but rather apply as much pain as you can consciously tolerate. There are two ways to manually pass yourself out. The first way is to hyperventilate yourself. Instead of taking regular, shallow breaths, start taking heavy, lung-filling breaths in and out. This disruption will actually mess up with the oxygen getting to your brain. You should go into a trance-like, painfree state just before you pass out. The second way of passing out is by crounching down and taking a few deep breaths. After 5 minutes of heavy breathing, exhale everything in your lungs and stand up quickly. The lack of blood and oxygen in your brain should knock you right out.
Stay Positive
The final, and most important, piece of advice is to never give up. When you give up hope psychologically, your body physically gives into the stress and begins to weaken and shut itself down. You must always remain calm and confident. Freaking, panicking and acting irrational is also negative. It puts additional stress on your body and mind and will only result in an increased probability of you dying.
That, in brief is how one would survive a torture situation. Once again, you should pray that you never have to draw upon any of these skills, but it's always good to be prepared. Try to stay safe and, no matter what, always be strong. Peace out, SuperSpy.