Considering the time-varying power consumption of users and cost of generation over a day, demand side management (DSM) has become essential to meet the excessive need of users with the limited source of power. In this paper, we propose a utility based optimal Real-Time Pricing (RTP) mechanism for the future smart grid communication systems such that the electricity price corresponds to the optimum system welfare. Here, we formulate a distributed algorithm which is based on the two-way communication among users, decision maker, and energy provider through the exchange of control messages, and determine the optimal price maintaining the equality between the total demand and the offered generation. We also propose a novel cost function for energy provider exhibiting how it reduces the impact of the change in user number to electricity price, unlike a previously proposed cost function. Simulation results confirm that the proposed algorithm is favorable for both the users and energy provider in terms of electricity price and generation cost respectively. It is also demonstrated that our new cost function makes the RTP algorithm user-adaptive and offers a better welfare to both the users and the energy provider.