Investigating the behaviors of impurities such as carbon, nitrogen and oxygen within tungsten is crucial to understanding the formation of compounds which can substantially influence the physical and chemical properties of tungsten. Using density functional theory method, we have investigated the geometry and energetics of small VacX(n), SolX(n) and SolVacX(n) (Vac = vacancy, Sol = solute, and X = C, N or O) clusters to probe the aggregation of X in tungsten. We find that vacancy and solute-vacancies show great attraction to X atoms and multiple X atoms can be embedded in the defects. Four C atoms segregate in a vacancy forming a square where the C-C bond forms with the bond length of 1.58 angstrom, however, it is hard to form N-N (or O-O) bonds in a vacancy although up to six N (or O) atoms can be trapped in a vacancy. The solutes titanium, tantalum, rhenium and osmium present relatively weak attraction to X atoms, and the binding energies of the solute with X rely on the bond length of Sol-X. Moreover, the concentration evolution of VacC(n) (SolC(n)) is determined through the law of mass action, and the results show that the concentrations of VacC(n) (SolC(n)) depend strongly on temperature, and the initial concentrations of vacancy (Sol) and C. The binding energy of SolVacX(n) correlates linearly with the volume difference of the system containing a SolVacX(n) and that with no defects. The aggregation of X atoms in the microstructure of tungsten, forming high X concentration zones, may facilitate the formation of compounds.