We all pray that no harm will ever come to us but sadly, that's not always the case. Since I'm the man who takes you under his wing, I'll teach you how to survive the unthinkable. One day, when you're a covert spy being tortured, you'll think back and thank me for this. Without further adieu, here's how you'll withstand torture.
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.
When you're being tortured, remember that you're lower than a piece of shit. You should be fearful and submissive at any moment. Though acting like a tough smartass may work for James Bond, it'll piss off your guards and label you as useless or uncooperative. That'll get you killed or tortured harder. Instead of being a rock, be more like a gelatine. Gelatine will mold, squish and give in to any sort of force but it will never let go of its moisture. In the same way, you should show pain (even exaggerate it) but you'll never let go of your information.
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.
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.