Assume that x is distributed according to a normal distribution with unknown mean
and precision
.

and that the prior distribution on
and
,
, has a normal-gamma distribution

for which the density π satisfies
![{\displaystyle \pi (\mu ,\tau )\propto \tau ^{\alpha _{0}-{\frac {1}{2}}}\,\exp[-\beta _{0}\tau ]\,\exp \left[-{\frac {\lambda _{0}\tau (\mu -\mu _{0})^{2}}{2}}\right].}](//wikimedia.org/api/rest_v1/media/math/render/svg/beb41e025bfbe7ea2f4087b48af2f9fb48b9c172)
Suppose

i.e. the components of
are conditionally independent given
and the conditional distribution of each of them given
is normal with expected value
and variance
The posterior distribution of
and
given this dataset
can be analytically determined by Bayes' theorem[4] explicitly,

where
is the likelihood of the parameters given the data.
Since the data are i.i.d, the likelihood of the entire dataset is equal to the product of the likelihoods of the individual data samples:

This expression can be simplified as follows:
![{\displaystyle {\begin{aligned}\mathbf {L} (\mathbf {X} \mid \tau ,\mu )&\propto \prod _{i=1}^{n}\tau ^{1/2}\exp \left[{\frac {-\tau }{2}}(x_{i}-\mu )^{2}\right]\\[5pt]&\propto \tau ^{n/2}\exp \left[{\frac {-\tau }{2}}\sum _{i=1}^{n}(x_{i}-\mu )^{2}\right]\\[5pt]&\propto \tau ^{n/2}\exp \left[{\frac {-\tau }{2}}\sum _{i=1}^{n}(x_{i}-{\bar {x}}+{\bar {x}}-\mu )^{2}\right]\\[5pt]&\propto \tau ^{n/2}\exp \left[{\frac {-\tau }{2}}\sum _{i=1}^{n}\left((x_{i}-{\bar {x}})^{2}+({\bar {x}}-\mu )^{2}\right)\right]\\[5pt]&\propto \tau ^{n/2}\exp \left[{\frac {-\tau }{2}}\left(ns+n({\bar {x}}-\mu )^{2}\right)\right],\end{aligned}}}](//wikimedia.org/api/rest_v1/media/math/render/svg/2af15facc697809f43f699f3db0ff784f59dea45)
where
, the mean of the data samples, and
, the sample variance.
The posterior distribution of the parameters is proportional to the prior times the likelihood.
![{\displaystyle {\begin{aligned}\mathbf {P} (\tau ,\mu \mid \mathbf {X} )&\propto \mathbf {L} (\mathbf {X} \mid \tau ,\mu )\pi (\tau ,\mu )\\&\propto \tau ^{n/2}\exp \left[{\frac {-\tau }{2}}\left(ns+n({\bar {x}}-\mu )^{2}\right)\right]\tau ^{\alpha _{0}-{\frac {1}{2}}}\,\exp[{-\beta _{0}\tau }]\,\exp \left[-{\frac {\lambda _{0}\tau (\mu -\mu _{0})^{2}}{2}}\right]\\&\propto \tau ^{{\frac {n}{2}}+\alpha _{0}-{\frac {1}{2}}}\exp \left[-\tau \left({\frac {1}{2}}ns+\beta _{0}\right)\right]\exp \left[-{\frac {\tau }{2}}\left(\lambda _{0}(\mu -\mu _{0})^{2}+n({\bar {x}}-\mu )^{2}\right)\right]\end{aligned}}}](//wikimedia.org/api/rest_v1/media/math/render/svg/de9c451b7469721ab4ef04a1df37564f2a9ad70b)
The final exponential term is simplified by completing the square.

On inserting this back into the expression above,
![{\displaystyle {\begin{aligned}\mathbf {P} (\tau ,\mu \mid \mathbf {X} )&\propto \tau ^{{\frac {n}{2}}+\alpha _{0}-{\frac {1}{2}}}\exp \left[-\tau \left({\frac {1}{2}}ns+\beta _{0}\right)\right]\exp \left[-{\frac {\tau }{2}}\left(\left(\lambda _{0}+n\right)\left(\mu -{\frac {\lambda _{0}\mu _{0}+n{\bar {x}}}{\lambda _{0}+n}}\right)^{2}+{\frac {\lambda _{0}n({\bar {x}}-\mu _{0})^{2}}{\lambda _{0}+n}}\right)\right]\\&\propto \tau ^{{\frac {n}{2}}+\alpha _{0}-{\frac {1}{2}}}\exp \left[-\tau \left({\frac {1}{2}}ns+\beta _{0}+{\frac {\lambda _{0}n({\bar {x}}-\mu _{0})^{2}}{2(\lambda _{0}+n)}}\right)\right]\exp \left[-{\frac {\tau }{2}}\left(\lambda _{0}+n\right)\left(\mu -{\frac {\lambda _{0}\mu _{0}+n{\bar {x}}}{\lambda _{0}+n}}\right)^{2}\right]\end{aligned}}}](//wikimedia.org/api/rest_v1/media/math/render/svg/be3f6e839a36bd0b1ccaf4ed857d7389eb834b50)
This final expression is in exactly the same form as a Normal-Gamma distribution, i.e.,

Interpretation of parameters
The interpretation of parameters in terms of pseudo-observations is as follows:
- The new mean takes a weighted average of the old pseudo-mean and the observed mean, weighted by the number of associated (pseudo-)observations.
- The precision was estimated from
pseudo-observations (i.e. possibly a different number of pseudo-observations, to allow the variance of the mean and precision to be controlled separately) with sample mean
and sample variance
(i.e. with sum of squared deviations
).
- The posterior updates the number of pseudo-observations (
) simply by adding the corresponding number of new observations (
).
- The new sum of squared deviations is computed by adding the previous respective sums of squared deviations. However, a third "interaction term" is needed because the two sets of squared deviations were computed with respect to different means, and hence the sum of the two underestimates the actual total squared deviation.
As a consequence, if one has a prior mean of
from
samples and a prior precision of
from
samples, the prior distribution over
and
is

and after observing
samples with mean
and variance
, the posterior probability is

Note that in some programming languages, such as Matlab, the gamma distribution is implemented with the inverse definition of
, so the fourth argument of the Normal-Gamma distribution is
.