Madrid is a genuinely safe city to walk around in, at night, alone, in most districts, which is more than can be said for a lot of places with better reputations. It also has a professional pickpocketing problem that is concentrated in a handful of locations and that operates by distraction rather than force. Almost nobody who is robbed here notices it happening. That sounds alarming and it is actually good news, because a non confrontational crime in a predictable place is one you can almost entirely design out of your trip.
The six places it actually happens
The pedestrian shopping streets between Sol and Gran Via, which are the highest density in the city.
Central metro interchanges and the trains running through them, particularly at rush hour and at closing time.
The airport metro line, where everybody is carrying luggage and looking at a map.
El Rastro on a Sunday morning, which puts a slow distracted crowd into narrow streets for four hours.
Plaza Mayor and Sol, where the crowd stops moving to take photographs.
Free entry queues at the big museums, which are the busiest hour of their day.
How it is done
Distraction, almost always: a question, a spill, dropped coins, a map held up, an argument nearby.
Teams of two or three, one to occupy you and one to take the bag.
The step onto a train, where the doors force everybody together for three seconds.
Bags on chair backs and phones on tables, on any terrace.
Fake petitions and bracelets near the main squares, which are a hand in your bag with a clipboard attached.
What to carry and how
Front pocket or inside zip for phone and wallet; never a back pocket.
Bag closed and worn across the front in any crowd.
One card and a day’s cash, with the rest left where you are staying.
A photograph of your passport stored somewhere you can reach without your phone.
Nothing valuable in an outside backpack pocket, which is behind you and out of sight.
A phone that is not in your hand on the pedestrian shopping streets.

Other practical safety notes
Unlicensed taxis at the airport and at stations, which are a pricing problem rather than a danger; use the ranks or an app.
Card machines: check the amount on the screen before you tap, and decline the offer to charge in your home currency.
Cash machines inside bank branches rather than standalone units on tourist streets.
Water in summer, because heat is a bigger practical risk here than crime.
Emergency help goes through the single European number, and the details of what happens next are worth reading before you need them.
Insurance claims require a police report filed in Spain, at the time.
Where this fits in a Madrid trip
None of this needs to change how you travel, only where your hands are for a few minutes a day.
For getting around the network where a good share of this happens, our guide to Madrid transport covers the tickets and the lines.
For what to do and who to call when something has actually gone wrong, our guide to emergency numbers in Madrid covers the specifics.
And for travelling here with children, where crowds and distraction are already the default, our guide to Madrid with kids covers the rhythm.

The short version
Madrid is safe and Madrid steals phones, and both are true. The risk lives on the pedestrian shopping streets, in the central metro interchanges, on the airport line, at El Rastro and in the crowd around Sol and Plaza Mayor. Carry your phone and wallet in a front or inside pocket, keep your bag closed and in front of you, and put nothing on the back of a chair. When something unexpected grabs your attention in a crowd, hand on the bag first. And buy insurance with a single item limit that would actually replace your phone.
