2 Samuel 17:1 Ahithophel said to Absalom, “I would[a] choose twelve thousand men and set out tonight in pursuit of David. 2 I would attack him while he is weary and weak. I would strike him with terror, and then all the people with him will flee. I would strike down only the king 3 and bring all the people back to you. The death of the man you seek will mean the return of all; all the people will be unharmed.” 4 This plan seemed good to Absalom and to all the elders of Israel.

5 But Absalom said, “Summon also Hushai the Arkite, so we can hear what he has to say as well.” 6 When Hushai came to him, Absalom said, “Ahithophel has given this advice. Should we do what he says? If not, give us your opinion.”

7 Hushai replied to Absalom, “The advice Ahithophel has given is not good this time. 8 You know your father and his men; they are fighters, and as fierce as a wild bear robbed of her cubs. Besides, your father is an experienced fighter; he will not spend the night with the troops. 9 Even now, he is hidden in a cave or some other place. If he should attack your troops first,(b) whoever hears about it will say, ‘There has been a slaughter among the troops who follow Absalom.’ 10 Then even the bravest soldier, whose heart is like the heart of a lion, will melt with fear, for all Israel knows that your father is a fighter and that those with him are brave.

11 “So I advise you: Let all Israel, from Dan to Beersheba—as numerous as the sand on the seashore—be gathered to you, with you yourself leading them into battle. 12 Then we will attack him wherever he may be found, and we will fall on him as dew settles on the ground. Neither he nor any of his men will be left alive. 13 If he withdraws into a city, then all Israel will bring ropes to that city, and we will drag it down to the valley until not so much as a pebble is left.”

14 Absalom and all the men of Israel said, “The advice of Hushai the Arkite is better than that of Ahithophel.” For the Lord had determined to frustrate the good advice of Ahithophel in order to bring disaster on Absalom.

a. 2 Samuel 17:1 Or Let me
b. 2 Samuel 17:9 Or When some of the men fall at the first attack

As the commentaries confirm, chapter 17 is a continuation of the events in chapter 16. The story continues with Absalom, Ahithophel and Hushai. Absalom, David's son, is getting advice from the two men whom David went to for advice. As a matter of fact Hushai is under cover for David.

So this is from Bible.org.

Ahithophel's counsel is exceedingly “shrewd” in several ways. First, it would have worked, barring the direct intervention of God. Second, it offered an appealing course of action to Absalom. He, not unlike his father David, can stay home from the battle and “make love” while Ahithophel and his army are making war with David. Absalom can quickly enter into his possession of the throne, yet without the dangers or discomforts of going into battle. As an added incentive, he can indulge himself with David's wives in a way that gets back at David and hurts and humiliates his father. Only David will be killed, who is Absalom's real enemy.

Ahithophel proposes a quick, easy victory for Absalom, won by Ahithophel while the “king” remains behind in Jerusalem. It is almost too good to be true. The fact is it would have worked, but God had other plans for David and for Absalom. Those plans are brought to pass through David's friends: Hushai, Zadok and Abiathar the priests, their sons Ahimaaz and Jonathan, a farmer's wife in Bahurim, and a number of other faithful friends and supporters of David. It is the story of David's deliverance we are now about to consider.

The attractiveness of Ahithophel's plan is that David can be defeated quickly and relatively easily, with a minimal loss of life and a nominal expenditure of energy. Absalom doesn’t need to go to battle at all. He can stay in Jerusalem with David's wives. Ahithophel will immediately set out with 12,000 soldiers and hunt David down, kill him alone, and bring David's followers to Absalom. The plan is also predicated upon certain assumptions. The assumption is that David is weary and defeated in spirit, that David has no will to fight and can be easily overcome. If this assumption is in error, the whole scheme Ahithophel proposes will collapse like a house of cards.

Hushai challenges the assumptions on which Ahithophel's plans are based, and thus the plans as well. He proposes a very different David, and thus a very different plan. Hushai insists that Ahithophel has dangerously underestimated David and his ability to defend himself and his kingdom. Hushai reminds Absalom and the elders of Israel about the kind of man David is. David is no mental weakling; he is a tough and seasoned warrior. Absalom's rebellion will not break David's spirit; it will antagonize him. He will be like a she-bear, deprived of her cubs. David will be fighting mad and fighting ready. If Ahithophel comes into the wilderness to attack David, they will fight him on his turf. After all, David has spent years hiding from Saul in the wilderness. Does Ahithophel really think David can easily be found sitting among the rest of the people? He will be hiding out, and when Ahithophel and his small army arrive, David will pounce on them, giving them a humiliating defeat. It will be Absalom's soldiers who will lose heart and run, not David or his men.

Hushai's plan brings about a bigger battle, so that not only will many of Absalom's supporters die, but Absalom himself will be killed, thus ending the revolution. Hushai's plan gives David the time he needs to get to his kind of battle -- guerrilla warfare. It lets him fight on his turf, so that the forest will kill more than his soldiers (18:8). Hushai's plan makes Ahithophel's counsel seem foolish, which is exactly what David has prayed for (15:31). It brings about the deliverance of David and the defeat of his enemies.

Hushai's plan is not as good as Ahithophel's plan. It really doesn't matter which plan is the best. God wants Hushai's plan to work because David is the anointed king, not Absalom. God wants David on the throne and that's the way it has to be. Absalom's need for revenge over the handling of his sister's rape is secondary to God's plans for the Nation of Israel.