Smart sensing and wireless communication technologies enable the electric power grid system to deliver electricity more efficiently through the dynamic analysis of the electricity demand and supply. The current solution is to extend the traditional static electricity pricing strategy to a time-based one where peak-time prices are defined to influence electricity usage behavior of customers. However, the time-based pricing strategy is not truly dynamic and the electricity resource cannot be optimally utilized in real time. In this paper, we propose a usage-based dynamic pricing (UDP) scheme for smart grid in a community environment, which enables the electricity price to correspond to the electricity usage in real time. In the UDP scheme, to simplify price management and reduce communication overhead, we introduce distributed community gateways as proxies of the utility company to timely respond to the price enquiries from the community customers. We consider both community-wide electricity usage and individual electricity usage as factors into price management: a customer gets higher electricity unit price if its own electricity usage becomes larger under certain conditions of the community-wide collective electricity usage. Additionally, we protect the privacy of the customers by restricting the disclosure of the individual electricity usage to the community gateways. Lastly, we provide privacy and performance analysis to demonstrate that the UDP scheme supports real-time dynamic pricing in an efficient and privacy-preserving manner.