Yes, Madrid is generally safe to visit.  Petty crimes, such as pickpocketing, can occur, especially in crowded areas like Puerta del Sol, Gran Vía, and public transport. Staying vigilant and keeping your belongings secure can help prevent these issues.
Public transport, including buses and the Metro, is safe and efficient. However, be cautious of your personal items, particularly during peak hours. Some neighborhoods may be less safe after dark, so it’s advisable to stay informed about the areas you plan to visit and follow advice from locals.