Community detection in networks has become a very important axis of research for understanding the structure of networks. Several methods have been proposed to detect the most optimal community structure in networks. In this article, we present a novel method for detecting community structure ComDBNS (Community Detection Based on Node Similarity) for unweighted and undirected networks; it performs in two steps. The first step uses the similarity between endpoints of each link to find the inter-community links to remove in order to create basic groups of nodes properly connected. In the second step we propose a strategy to merge these initial groups to identify the final community structure (with k communities or the structure that maximizes the modularity in Community Detection Based on Node Similarity and Modularity Q (ComDBNSQ)). The proposed method is tested on the real and computer-generated networks, and it demonstrates the effectiveness and correctness of the method. Also, the method saves the time complexity.