The nitrogen and fluorine co-doped TiO2 (N-F-TiO2) nanoparticles of anatase crystalline structure were prepared by a facile method of (NH4)(2)TiF6 pyrolysis, and characterized by thermogravimetry-differential thermal analysis (TG-DTA), X-ray diffraction (XRD), transmission electron microscopy (TEM), X-ray photoelectron spectroscopy (XPS), and ultraviolet visible (UV-Vis) spectroscopy etc. With the increase of calcination temperature, (NH4)(2)TiF6 decomposed into TiOF2 and NH4TiOF3 at first, and then formed anatase-type TiO2 with thin sheet morphology. H3BO3 as oxygen source can promote the formation of anatase TiO2, but decrease the F content in the N-F-TiO2 materials due to the formation of volatile BF3 during the precursor decomposition. The photocatalytic activity of the obtained N-F-TiO2 samples was evaluated by the methylene blue degradation under visible light, and all the samples exhibited much higher photocatalytic activity than P25. Moreover, the merits and disadvantages of this proposed method to prepare doped TiO2 are discussed.