How to calculate how many photons are in the universe? The "universe" is a sphere with a radius of $10^{25}$ m 
 the medium temperature is 3K, 
 how many photons there are in the universe?
$$n_\gamma =  \int_{0}^{\infty}  \frac{8h\pi\nu^3} {{c^3}{}} \frac{1} {{e^\frac{h\nu} {KT} -1}{}}d\nu = 2.4\frac{8\pi} {c^3} (\frac{KT} {h})^3 \simeq 1.64* 10^{17} photons$$ 
but according to previous answers and other references...
e.g.
https://www.quora.com/How-many-photons-are-there-in-the-universe
the number is much bigger $$10^{89} $$
where is the problem in my tentative?
As you can see in my tentative, I would be better if the answer is based on "classical thermodynamic" using plack distribution, and a boltzmann-like point of view.
Estimation based on cosmological facts are also welcome.
When you solve the integral while you do some substitution you have to solve an integral like this $$ \int_{0}^{\infty}  \frac{x^2} {{e^x -1}{}} dx \simeq2.4$$
 A: Besides using a too small value for the radius of the Universe — which is in fact some 46 billion lightyears, or $R_\mathrm{Uni}\sim4\times10^{28}\,\mathrm{cm}$ — I think you've just made a simple calculation error (my guess is mixing SI and cgs units):
Your result for $n_\gamma$ ("$1.64\times10^{17}$ photons") is a number, whereas in fact the result should be a number density, measured e.g. in $\mathrm{cm}^{-3}$. This value should then be multiplied by the volume of the (observable) Universe.
Photons $\simeq$ CMB photons
The number of photons in the Universe is dominated by the CMB photons, by over two orders of magnitude (see this answer for a discussion of the Universal photon background). Each $\mathrm{cm}^3$ of space holds roughly $n_\gamma = 410$ CMB photons, which I estimate from observations in that answer, but which is indeed also what I get with your own calculation.
If you include all photons — not just CMB photons, but also radio, IR, optical, etc. — the result is $n_\gamma\simeq413\,\mathrm{cm}^{-3}$).
Hence, with a volume of $V_\mathrm{Uni} = 4\pi R_\mathrm{Uni}^3/3 = 3.5\times10^{86}\,\mathrm{cm}^3$ — the total number of photons is
$$
N = n_\gamma V_\mathrm{Uni} = 1.4\times10^{89}\,\mathrm{photons}.
$$

As has been commented above, the number of photons is not really conserved. However, the amount of CMB photons that has been absorbed since they were emitted is actually negligible. The only interactions of these photons that alter their state is scattering on free electrons after the Universe was reionized (which happened 0.5 to 1 billion years after they were emitted). The optical depth to this so-called Thompson scattering is $\tau = 0.066$ (Planck collaboration 2015), so the fraction of CMB photons that have scattered is $1 - e^{-0.066} = 0.06$. But this process doesn't remove any photons from the budget, it only polarizes them.
A: You can convert the Planck function into the phase space number density of photons: $$n(\mathbf{x}, \mathbf{p}) = \frac{2}{h^3 \left[\operatorname{exp}\left(\frac{pc}{kT}\right) - 1\right]}. $$ Integrating that expression over both space and momenta gives a formula for the total number of photons: $$\begin{align} N & = \frac{8\pi V}{h^3} \left[\frac{kT}{c}\right]^3 \int_0^\infty \frac{u^2}{\operatorname{e}^u - 1} \operatorname{d} u \\
& = 16 \pi V \left[\frac{kT}{hc}\right]^3 \zeta(3),\end{align}$$
c.f. the expression for $N$ in Wikipedia's photon gas article.
Using just the Cosmic Microwave Background (CMB), which is extremely close to a blackbody, will be a slight underestimate because it doesn't account for newly emitted light in the last 13 billion years or so, but not by much. The density of energy stored in the electromagnetic field is dominated by the CMB and, since it has mean frequency lower than most photons emitted since, the density of photons will be even more dominated by the CMB than the energy is.
For more, see this 2016 review by Cooray, especially Figure 1.
