We develop the stochastic approach to thermodynamics based on the stochastic dynamics, which can be discrete (master equation) continuous (Fokker-Planck equation), and on two assumptions concerning entropy. The first is the definition of entropy itself and the second, the definition of entropy production rate which is nonnegative and vanishes in thermodynamic equilibrium. Based on these assumptions we study interacting systems with many degrees of freedom in equilibrium or out of thermodynamic equilibrium, and how the macroscopic laws are derived from the stochastic dynamics. These studies include the quasi-equilibrium processes, the convexity of the equilibrium surface, the monotonic time behavior of thermodynamic potentials, including entropy, the bilinear form of the entropy production rate, the Onsager coefficients and reciprocal relations, and the nonequilibrium steady states of chemical reactions.