The only way to destroy the Ring is by throwing it into the fire of Orodruin. This fact doesn't seem to be common knowledge and many people in the story (like Gimli) only learn about it at the council in Rivendell. How come Gandalf and Elrond know about this? And why are they so sure that it is the only way to destroy it? Taking the ring to Mordor means taking a great risk, so they must have been really confident that it is the only option. Where did they gain that knowledge?
Knowledge of how to destroy the Ring dates back to at least the end of the Second Age, after Isildur took the Ring, and as described in the chapter The Council of Elrond:
'Alas! yes,' said Elrond. 'Isildur took it, as should not have been. It should have been cast then into Orodruin's fire nigh at hand where it was made. But few marked what Isildur did. He alone stood by his father in that last mortal contest; and by Gil-galad only Círdan stood, and I. But Isildur would not listen to our counsel.'
It's notable that this occurred before Gandalf (or Saruman, for that matter) arrived in Middle-earth, and that Elrond and Círdan are (at that time) both Ringbearers: Elrond holding Vilya and Círdan Narya.
It may be assumed that Gandalf (and Saruman) received this information from either Elrond or Círdan (or both), and it must be concluded that this information therefore did not come from Ring research by any of the Istari, since it was clearly known before they arrived.
In Of the Rings of Power and the Third Age we read the following:
But the Elves were not so lightly to be caught. As soon as Sauron set the One Ring upon his finger they were aware of him; and they knew him, and perceived that he would be master of them, and of all that they wrought.
This seems the most likely source of the knowledge of where and how the One Ring must be destroyed. Otherwise it is not explicitly stated anywhere.
As Victim of Circumstance makes clear in his answer, the fact that the One Ring could be destroyed at Mount Doom was known to the elves at the end of the second age, and this information probably came from Celebrimbor. However, at the Council of Elrond, Elrond says
Gandalf has revealed to us that we cannot destroy it by any craft that we here possess.
So, the elves did not know that the ring could only be destroyed at Mount Doom. Only Gandalf seems to have known any more about the destruction of Rings of Power, and he knew a lot. Aside from pointing out that the Elves could not destroy the One (and that dragons destroyed four of the Seven), Gandalf rules out several other possibilites:
... he [Tom Bombadil] cannot alter the Ring itself.
(The Council of Elrond)
Not even the anvils and furnaces of the Dwarves could do that.
(The Shadow of the Past)
... nor was there ever any dragon, not even Ancalagon the Black, who could have harmed the One Ring, the Ruling Ring, for that was made by Sauron himself.
(The Shadow of the Past)
In fact, Gandalf states unequivocally that
There is only one way: to find the Cracks of Doom in the depths of Orodruin, the fire-mountain, and cast the Ring in there.
(The Shadow of the Past).
I think it's important to stress that Ancalagon (had he been alive) could not destroy the Ring because it was 'made by Sauron himself'. My own reading of this is that Gandalf knew destroying the ring without returning it to Mount Doom would require a power greater than Sauron's. How else could he have known that no other method would work, when none had been tried? However, as Gandalf himself puts it:
I knew much and I have learned much. But I am not going to give an account of all my doings to you.
It was an intelligent guess, presumably made by Elrond during the Second Age
Since it was forged by Sauron in Orodruin itself, it was generally assumed that the One Ring could only be destroyed in the same fire that "created" it. Forging in a real world context literally involves the material to be melted (slightly) first, and then shaped into an object, which is in this case, a Ring. If the fires were hot enough to melt it the first time, it would definitely be hot enough to melt it again.
What did the Elves know about the Ring?:
The Elves knew that an all-powerful and all-dominant Ring was forged by Sauron in Mount Doom, thanks to Celebrimbor, who perceived Sauron when he first put on the Ring.
But the Elves were not so lightly to be caught. As soon as Sauron set the One Ring upon his finger they were aware of him; and they knew him, and perceived that he would be master of them, and of an that they wrought. Then in anger and fear they took off their rings.
The Silmarillion, Of the Rings of Power and the Third Age
This information was very likely to have been relayed down to Galadriel and Gil-galad when Celebrimbor gave them the Elven Rings, and to Elrond and Cirdan when Gil-galad passed them his Rings.
What didn't the Elves know about the Ring?:
How, exactly, to destroy it. Putting two-and-two together, they reckoned that the Ring could only be destroyed in the place it was made in.
'Alas! yes,' said Elrond. 'Isildur took it, as should not have been. It should have been cast then into Orodruin's fire nigh at hand where it was made. But few marked what Isildur did. He alone stood by his father in that last mortal contest; and by Gil-galad only Cirdan stood, and I. But Isildur would not listen to our counsel.
The Lord of the Rings: The Fellowship of the Ring, Book II, Chapter II, The Council of Elrond
The Ruling Ring passed out of the knowledge even of the Wise in that age; yet it was not unmade. For Isildur would not surrender it to Elrond and Círdan who stood by. They counselled him to cast it into the fire of Orodruin nigh at hand, in which it had been forged, so that it should perish, and the power of Sauron be for ever diminished, and he should remain only as a shadow of malice in the wilderness.
The Silmarillion, Of the Rings of Power and the Third Age
Second Age: So when the time came to destroy the Ring, Elrond and Cirdan counselled Isildur to destroy it in the fires where it was forged.
Third Age: Fast forward, Elrond merely repeats this information at the Council of Elrond.
Third Age onwards: Thereafter this so-called "information on how to destroy the Ring" was taken up by the Istari, who came only at around Third Age Year 1000-ish. Saruman, being a Maia of Aule himself, might have given his two-cents on how the Ring could be destroyed (when he was still "good"), but this cannot be confirmed.
As far as we know, as this is never discussed explicitly, it can be assumed as an intelligent guess.
This is only a theory. There doesn't seem to be a definitive answer.
The Council of Elrond didn't know how to destroy the ring, not with certainty. They gathered the best experts available to discuss the possibility. Throwing it into Orodruin was their best guess, not their definitive solution.
From a narrative standpoint, this makes Frodo's errand even more desperate. If they'd guessed wrong, Sauron would have the ring back, and he would rule Middle-earth.
The Ainur may be childlike, but they aren't stupid.
Sauron forged the One Ring in Orodruin. This requires it to be hot enough to melt. We know that it was at one point melted, because Sauron emblazoned it with a little poetry written in his pet conlang.
He also funneled a large slice of his fëa (read: SOUL) into it. Saruman and Gandalf would know this - Saruman being an engineer, and Gandalf being the bearer of one of the Three Rings (and therefore having a connection to the One). This is why it corrupts its non-hobbit bearers: Sauron literally has a telepathic connection to the present ringbearer. (Hobbits are less affected because they are naturally resistant to telepathy.)
Therefore, throwing the One into Orodruin would melt the Ring, and destroy the energy pattern locked inside it, thereby killing Sauron.
(Of course, Saruman had planned to extract Sauron's fëa from the Ring so it could be safely used by anyone, but that didn't go through.)
Gandalf is one of the lesser gods of creation, the Maiar, what he does and doesn't know is never made clear but as a servant of Eru Ilúvatar his power in Arda is almost limitless, although the restraints placed on it's use are almost total, but his knowledge base is unavoidably huge. He arrives in Middle-Earth after the fall of Númenor and Eregion to Sauron's machinations and the sealing off of the utmost west, therefore he knows the history of the One Ring (I seem to recall that he's one of the Maiar who is actually there when Númenor and Eregion go down in ruin, or just before, but I could be wrong). He actually knows more about the Ring than he does about Middle-Earth, he's not native to the world we see him in when we read The Lord of the Rings. There's a lot about this in the appendices at the end of The Lord of the Rings, more of it, in particular the origins of the Wizards, is in The Book of Lost Tales under Istari but most of it is in The Silmarillion, particularly the fall of Númenor and Eregionand the end of the second age, which is a heavy read to say the least but worthwhile if you actually want to understand the world of Tolkien.
Edit: Apparently I'm wrong and Gandalf doesn't know what's going on, Celebrimbor doesn't make it out of Eregion but Elrond does, he may or may not know what's going on, Celebrimbor is a ring-smith in his own right it would make sense for him to know but he's dead.