The derivation starts from defining entropy as S = k ln W, with W the number of microstates in the microcanonical ensemble where all microstates are equally likely. The addition rule for entropy and multiplicativity of microstates imply a logarithmic relation with positive scaling constant k. The Gibbs paradox arises because treating particles as distinguishable leads to a nonzero mixing entropy when identical gases mix, contradicting physical intuition. This is resolved by recognizing indistinguishability, introducing the 1/N! factor in the partition function to avoid overcounting microstates, which restores entropy extensivity and eliminates unphysical mixing entropy for identical gases.
In statistical mechanics the entropy is the quantity that makes the equilibrium probabilities reproduce the thermodynamic laws. For a system in contact with a heat bath at temperature (T) the equilibrium distribution is the canonical one
[
p_i=\frac{1}{Z},\mathrm{e}^{-\beta E_i},\qquad Z=\sum_i \mathrm{e}^{-\beta E_i},
]
and the appropriate definition of entropy is the Shannon–Gibbs functional
[
S[p] = -,k_{\rm B}\sum_i p_i\ln p_i,
]
because with this choice the thermodynamic relations (T^{-1}=\partial S/\partial U), (F=U-TS=-k_{\rm B}T\ln Z), etc., are recovered. In the special case of the microcanonical ensemble all (W) accessible microstates are equally probable, (p_i=1/W), so this reduces to
[
S=-k_{\rm B} W\times \frac{1}{W},\ln \frac{1}{W}=k_{\rm B}\ln W,
]
Boltzmann’s famous formula.
The Gibbs paradox arises if you try to apply that formula with a naïve classical counting of states. If you mix (N) molecules of an ideal gas with another (N) molecules of the same gas at the same (T) and (p), the classical mixing entropy formula (\Delta S=2Nk_{\rm B}\ln 2) suggests an increase, although macroscopically nothing changes. The resolution is that the overcounting of microstates for identical particles makes (W) too large. Permuting identical particles does not produce a new microstate, so the correct classical partition function and state count carry a factor of (1/N!):
[
Z_N=\frac{1}{N!}\Bigl(Z_1\Bigr)^N,\qquad W\propto\frac{\text{phase space volume}^N}{N!}.
]
With this indistinguishability factor the entropy becomes extensive and the extra (\ln N!) terms cancel the spurious (\ln 2) mixing term when the two samples are of the same species. If the two gases are different, no such cancellation occurs and mixing produces a genuine entropy increase, in agreement with experiment.