A general theory of optimal natural dualities is presented, built on the test algebra technique introduced in an earlier paper. Given that a set R R of finitary algebraic relations yields a duality on a class of algebras A = I S P ( M _ ) \mathcal {A} = \operatorname {\mathbb {I}\mathbb {S}\mathbb {P}}( \underline {M}) , those subsets R ′ R’ of R R which yield optimal dualities are characterised. Further, the manner in which the relations in R R are constructed from those in R ′ R’ is revealed in the important special case that M _ \underline {M} generates a congruence-distributive variety and is such that each of its subalgebras is subdirectly irreducible. These results are obtained by studying a certain algebraic closure operator, called entailment, definable on any set of algebraic relations on M _ \underline {M} . Applied, by way of illustration, to the variety of Kleene algebras and to the proper subvarieties B n \mathbf {B}_{n} of pseudocomplemented distributive lattices, the theory improves upon and illuminates previous results.