Refinements of the classical Sobolev inequality lead to optimal domain problems in a natural way. This is made precise in recent work of Edmunds, Kerman and Pick; the fundamental technique is to prove that the (generalized) Sobolev inequality is equivalent to the boundedness of an associated kernel operator on [0,1]. We make a detailed study of both the optimal domain, providing various characterizations of it, and of properties of the kernel operator when it is extended to act in its optimal domain. Several results are devoted to identifying the maximal rearrangement invariant space inside the optimal domain. The methods and techniques used involve interpolation theory, Banach function spaces and vector integration.