Optical-to-electrical conversion, which is the basis of the operation of optical detectors, can be linear or nonlinear. When high sensitivities are needed, single-photon detectors are used, which operate in a strongly nonlinear mode, their response being independent of the number of detected photons. However, photon-number-resolving detectors are needed, particularly in quantum optics, where n-photon states are routinely produced. In quantum communication and quantum information processing, the photon-numberre-solving functionality is key to many protocols, such as the implementation of quantum repeaters(1) and linear- optics quantum computing(2). A linear detector with single-photon sensitivity can also be used for measuring a temporal waveform at extremely low light levels, such as in long-distance optical communications, fluorescence spectroscopy and optical time-domain reflectometry. We demonstrate here a photon-number-resolving detector based on parallel superconducting nanowires and capable of counting up to four photons at telecommunication wavelengths, with an ultralow dark count rate and high counting frequency.