In this paper, we study the grid based routing scheme of wireless sensor networks. First, by considering the transmission cost, the selection of the distance between grid nodes is mathematically analyzed. The optimal grid distance, which has the least transmission cost, is obtained to be the square root of the ratio between the radio energy dissipation and the amplifier energy dissipation. Based on the derived grid distance, a cost parameter is defined as the metric for the selection of a grid node by considering its residual power and the location. And this parameter is further applied for the routing of the forwarding of sensed information. In addition, for the case of one sink node with multiple sources, the scheme of aggregation for multiple grid topologies is proposed. The performance of the proposed scheme is examined through simulations by using NS2. Our results illustrate that the proposed routing scheme can effectively lengthen the life time of the network.