According to the second law, the entropy of an isolated system increases during its evolution from one equilibrium state to another. The free expansion of a gas, on removal of a partition in a box, is an example where we expect to see such an increase of entropy. The construction of an entropy function, defined out of equilibrium, and that can be computed for a single microstate of a system (as opposed to an ensemble) is a non-trivial and subtle issue. It requires the idea of coarse-graining, definition of appropriate macrostates and the use of the Boltzmann entropy as opposed to the Gibbs entropy. We provide an explicit demonstration of these ideas in the context of free expansion of an ideal gas in one dimensions. Two definitions of entropy are considered --- one corresponding to the single particle empirical density leading to the Boltzmann H-function and another corresponding to a macrostate defined by the conserved fields of density, momentum and energy. It is found that only the second definition gives a monotonically increasing function. Both numerical and analytical results are presented.