There are many situations where one imposes certain conditions on a function and its Fourier transform and then wants to optimize a certain quantity. I will describe how these types of Fourier optimization problems can arise in the context of the explicit formula, which relates the primes to the zeros of the Riemann zeta-function. These ideas lead to the strongest known estimates in the classical problem of bounding the maximum gap between consecutive primes assuming the Riemann hypothesis. Our answer depends on the size of the constant in the Brun-Titchmarsh inequality. Using the explicit formula in the other direction, we can also use Fourier optimization to prove the strongest known conditional estimates for the number of zeta zeros in an interval on the critical line. This is based on joint works with E. Carneiro, V. Chandee, and K. Soundararajan.