The paper presents the group theory of optimally-localized and symmetry-adapted Wannier functions in a crystal of any given space group G or magnetic group M. Provided that the calculated band structure of the considered material is given and that the symmetry of the Bloch functions at all of the points of symmetry in the Brillouin zone is known, the paper details whether or not the Bloch functions of particular energy bands can be unitarily transformed into optimally-localized Wannier functions symmetry-adapted to the space group G, to the magnetic group M or to a subgroup of G or M. In this context, the paper considers usual, as well as spin-dependent Wannier functions, the latter representing the most general definition of Wannier functi...