We prove the optimality of the Gagliardo–Nirenberg inequality: $$\begin{aligned} \Vert \nabla u\Vert _{X}\lesssim \Vert \nabla ^2 u\Vert _Y^{1/2}\Vert u\Vert _Z^{1/2}, \end{aligned}$$
‖
∇
u
‖
X
≲
‖
∇
2
u
‖
Y
1
/
2
‖
u
‖
Z
1
/
2
,
where Y and Z are rearrangement invariant Banach function spaces, and $$X = Y^{1/2}Z^{1/2}$$
X
=
Y
1
/
2
Z
1
/
2
is the Calderón–Lozanovskii space. By optimality, we mean that for a certain pair of spaces on the right-hand side, it is not possible to reduce the space on the left-hand side while remaining in the class of rearrangement invariant spaces. Our result establishes the optimality for Lorentz and Orlicz spaces, surpassing previous findings. Additionally, we discuss the significance of pointwise inequalities and present a counterexample that prohibits further improvements.