A method for encapsulating nanoparticles with an encapsulating matrix that minimizes aggregation and maintains favorable properties of the nanoparticles. The matrix comprises silicon-based network-forming compounds such as ormosils and polysiloxanes. The nanoparticles are synthesized from precursors directly within the silicon-based matrix.