Intermediate dimensions were recently introduced to provide a spectrum of dimensions interpolating between Hausdorff and box-counting dimensions for fractals where these differ. In particular, the self-affine Bedford-McMullen carpets are a natural case for investigation, but until now only very rough bounds for their intermediate dimensions have been found. In this paper, we determine a precise formula for the intermediate dimensions dimθΛ of any Bedford-McMullen carpet Λ for the whole spectrum of θ∈[0,1], in terms of a certain large deviations rate function. The intermediate dimensions exist and are strictly increasing in θ, and the function θ↦dimθΛ exhibits interesting features not witnessed on any previous example, such as having countab...