Detecting communities in real world networks is an important problem for data analysis in science and engineering. By clustering nodes intelligently, a recursive algorithm is designed to detect community. Since the relabeling of nodes does not alter the topology of the network, the problem of community detection corresponds to the finding of a good labelling of nodes so that the adjacency matrix form blocks. By putting a fictitious interaction between nodes, the relabeling problem becomes one of energy minimization, where the total energy of the network is defined by putting interaction between the labels of nodes so that the clustering of nodes in the same community will decrease the total energy. A greedy algorithm is used for the computation of minimum energy. The method shows efficient detection of community in artifical as well as real world network. The result is illustrated in a tree showing hierarchical structure of communities on the basis of sub-matrix density.