Yes, Barcelona and Madrid is safe for tourism, but tourists can be easy prey for pickpockets. There is little violent crime and few unsafe areas but compared to barcelona, Madrid is safe destination but it is also huge city! Both are very beautiful cities in Spain.