We prove a sharp integral inequality for the dyadic maximal function of φ ∈ L p . This inequality connects certain quantities related to integrals of φ and the dyadic maximal function of φ, under the hypothesis that the variables X φ dµ = f, X φ q dµ = A, 1 < q < p, are given, where 0 < f q ≤ A. Additionally, it contains a parameter β > 0 which when it attains a certain value depending only on f, A, q, the inequality becomes sharp. Using this inequality we give an alternative proof of the evaluation of the Bellman function related to the dyadic maximal operator of two integral variables.