Mobile ad hoc networks are highly susceptible to routing attacks because of their dynamic topology and lack of any infrastructure. Two of the major routing attacks are black hole and gray hole attacks. In a black hole attack, malicious node diverts most of the traffic in the network to itself, and later dumps it. A gray hole attack is a variation of the black hole attack, which changes its state from honest to malicious and vice versa. In this paper, the authors have illustrated an algorithm to detect Gray hole attacks in MANET, which leads to improved network performance in terms of performance metrics.