In this paper, using properties of Ramanujan sums and of the discrete Fourier transform of arithmetic functions, we give an explicit formula for the number of solutions of the linear congruence a1x1+⋯+akxk≡b(modn), with gcd(xi,n)=ti (1≤i≤k), where a1,t1,…,ak,tk,b,n (n≥1) are arbitrary integers. As a consequence, we derive necessary and sufficient conditions under which the above restricted linear congruence has no solutions. The number of solutions of this kind of congruence was first considered by Rademacher in 1925 and Brauer in 1926, in the special case of ai=ti=1(1≤i≤k). Since then, this problem has been studied, in several other special cases, in many papers; in particular, Jacobson and Williams [Duke Math. J. 39 (1972) 521–527] gave a nice explicit formula for the number of such solutions when (a1,…,ak)=ti=1(1≤i≤k). The problem is very well-motivated and has found intriguing applications in several areas of mathematics, computer science, and physics, and there is promise for more applications/implications in these or other directions.