For a system of N spins there are quantum states that can encode a directio
n in an intrinsic way. Information on this direction can later be decoded b
y means of a quantum measurement. We present here the optimal encoding and
decoding procedure using the fidelity as a figure of merit. We compute the
maximal fidelity and prove that it is directly related to the largest zeros
of the Legendre and Jacobi polynomials. We show that this maximal fidelity
approaches unity quadratically in 1/N. We also discuss this result in term
s of the dimension of the encoding Hilbert space.