For a non-degenerate integral quadratic form F (x 1 , . . . , x d ) in d ≥ 5 variables, we prove an optimal strong approximation theorem. Let Ω be a fixed compact subset of the affine quadric F (x 1 , . . . , x d ) = 1 over the real numbers. Take a small ball B of radius 0 < r < 1 inside Ω, and an integer m. Further assume that N is a given integer which satisfies N ≫ δ,Ω (r −1 m) 4+δ for any δ > 0. Finally assume that an integral vector (λ 1 , . . . , λ d ) mod m is given. Then we show that there exists an integral solution X = (x 1 , . . . , x d ) of F (X) = N such that x i ≡ λ i mod m and X √ N ∈ B, provided that all the local conditions are satisfied. We also show that 4 is the best possible exponent. Moreover, for a non-degenerate integral quadratic form in 4 variables we prove the same result if N is odd and N ≫ δ,Ω (r −1 m) 6+ǫ . Based on our numerical experiments on the diameter of LPS Ramanujan graphs and the expected square root cancellation in a particular sum that appears in Remark 6.8, we conjecture that the theorem holds for any quadratic form in 4 variables with the optimal exponent 4.