Madrid is a fairly safe city with very little violent crimes. The two biggest dangers you’ll face in Madrid are traffic and pickpockets.
Spain is known for its astronomical level of car related deaths. Ensure that you cross at designated crossing areas, and even then, check both ways before crossing. When driving, it is best to adhere strictly to the rules of the road and drive defensively.
Muggings are not very common in Madrid, but pick pocketing is rampant. Pickpockets often work in teams in order to distract you. Be especially careful when you first arrive in the city, as pickpockets target tourists and areas in which tourists are frequently found, such as Atocha and Sol. Cramped metro trains and buses, also create the perfect pick pocketing environment.