The classical Brun--Titchmarsh theorem gives an upper bound, which is of correct order of magnitude in the full range, for the number of primes p⩽x satisfying p≡amodq. We strengthen this inequality for different ranges of logq/logx, improving upon previous works by Motohashi, Goldfeld, Iwaniec, Friedlander and Iwaniec, and Maynard for general or special moduli. In particular, we are able to beat Iwaniec's barrier $q