Optical-to-electrical conversion, which is the basis of theoperation of optical detectors, can be linear or nonlinear.When high sensitivities are needed, single-photon detectorsare used, which operate in a strongly nonlinear mode, theirresponse being independent of the number of detectedphotons. However, photon-number-resolving detectors areneeded, particularly in quantum optics, where n-photon statesare routinely produced. In quantum communication andquantum information processing, the photon-numberresolvingfunctionality is key to many protocols, such as theimplementation of quantum repeaters1 and linear-opticsquantum computing2. A linear detector with single-photonsensitivity can also be used for measuring a temporalwaveform at extremely low light levels, such as in longdistanceoptical communications, fluorescence spectroscopyand optical time-domain reflectometry. We demonstrate here aphoton-number-resolving detector based on parallelsuperconducting nanowires and capable of counting up to fourphotons at telecommunication wavelengths, with an ultralowdark count rate and high counting frequency.