  Single-photon detectors are ubiquitous and integral components of photonic
quantum cryptography, communication, and computation. Many applications,
however, require not only detecting the presence of any photons, but
distinguishing the number present with a single shot. Here, we implement a
single-shot, high-fidelity photon number-resolving detector of up to 15
microwave photons in a cavity-qubit circuit QED platform. This detector
functions by measuring a series of generalized parity operators which make up
the bits in the binary decomposition of the photon number. Our protocol
consists of successive, independent measurements of each bit by entangling the
ancilla with the cavity, then reading out and resetting the ancilla. Photon
loss and ancilla readout errors can flip one or more bits, causing nontrivial
errors in the outcome, but these errors have a traceable form which can be
captured in a simple hidden Markov model. Relying on the independence of each
bit measurement, we mitigate biases in ensembles of measurements, showing good
agreement with the predictions of the model. The mitigation improves the
average total variation distance error of Fock states from $13.5\%$ to $1.1\%$.
We also show that the mitigation is efficiently scalable to an $M$-mode system
provided that the errors are independent and sufficiently small. Our work
motivates the development of new algorithms that utilize single-shot,
high-fidelity PNR detectors.
