the Gibbs entropy formula
A more general definition of entropy that works for any ensemble, not just for an isolated system. Instead of counting equally likely microstates, it weights each microstate by its own probability. Picture a probability distribution spread over microstates: the more spread out and uncertain the distribution, the higher the entropy; a distribution concentrated on a single microstate has zero.
Precisely, S = -k_B sum_i p_i ln p_i, summed over all microstates i, with p_i their probabilities. When all W accessible states are equally likely, p_i = 1/W, it reduces exactly to the Boltzmann formula S = k_B ln W. In the canonical ensemble, where p_i = e^(-beta E_i)/Z, substituting gives S = (<E> - F)/T = k_B (ln Z + beta <E>), recovering thermodynamics. The formula has the same shape as Shannon's information entropy, with k_B set to one and the logarithm taken in base two.
It is the master definition, valid in the canonical and grand canonical ensembles where the microstate probabilities are unequal. Two honest caveats: for a classical continuous system it needs the h^(3N) N! measure to be finite and to match thermodynamics; and the fine-grained Gibbs entropy of an isolated system is exactly conserved under Hamiltonian (Liouville) evolution, so the second-law increase requires coarse-graining or the equilibrium entropy, a subtle and important point.
A fair coin has two equally likely microstates, so S = -k_B (1/2 ln 1/2 + 1/2 ln 1/2) = k_B ln 2; a biased coin that always lands heads has p = 1 and S = 0, no uncertainty, no entropy.
Entropy measures the spread of the probability distribution over microstates.
The fine-grained Gibbs entropy of an isolated system is exactly constant under Liouville evolution; the second-law increase refers to the coarse-grained or equilibrium entropy, not this microscopic sum.