HADES is a versatile magnetic spectrometer aimed at studying dielectron production in pion, proton and heavy-ion induced collisions. Its main features include a ring imaging gas Cherenkov detector for electron-hadron discrimination, a tracking system consisting of a set of 6 superconducting coils producing a toroidal field and drift chambers and a multiplicity and electron trigger array for additional electron-hadron discrimination and event characterization. A two-stage trigger system enhances events containing electrons. The physics program is focused on the investigation of hadron properties in nuclei and in the hot and dense hadronic matter. The detector system is characterized by an 85% azimuthal coverage over a polar angle interval from 18 to 85 degree, a single electron efficiency of 50% and a vector meson mass resolution of 2.5%. Identification of pions, kaons and protons is achieved combining time-of-flight and energy loss measurements over a large momentum range. This paper describes the main features and the performance of the detector system.