Gandalf first suspected that the ring had power over Bilbo when he refuses to give it up.
Gandalf’s suspicions about Bilbo’s ring dated back to when he first got it from Gollum. Bilbo did not want to tell the truth about the ring from the beginning. He said that Gollum gave him a ring given to him long ago on his birthday when he won the game. Gandalf was suspicious.
Gandalf, however, disbelieved Bilbo's first story, as soon as he heard it, and he continued to be very curious about the ring. Eventually he got the true tale out of Bilbo after much questioning… (Prologue)
Knowing what he did about magic rings, Gandalf was aware that Bilbo might have the ring of power and not even know it. He also realized that Bilbo was in danger, and even though he had been able to resist the ring for this long it was beginning to affect him. The ring had given to Bilbo an unnaturally long life, and he had remained uncorrupted because he did not use it. He also did not kill anyone to get it. However, Bilbo was beginning to heed the call to adventure, and the ring was longing to go home.
When Bilbo calls the ring “precious,” Gandalf is aware that it is beginning to take ahold on him.
The wizard's face remained grave and attentive, and only a flicker in his deep eyes showed that he was startled and indeed alarmed. 'It has been called that before,' he said, 'but not by you.' (Ch. 1)
Bilbo recovers quickly from his momentary lapse, and does not know what has come over him. Gandalf, however, has seen the signs, and knows that this means trouble. Bilbo has held onto the ring too long. He is beginning to act and sound like Gollum. The ring is influencing him, digging in its metaphorical claws. Gandalf knows that Bilbo must free himself from the ring and he gets him to give it to Frodo, who is as of yet innocent of the ring’s pull. Frodo must take the ring to Mordor and destroy it for good.