The short answer is roughly 20 years. The passing of the ring from Bilbo to Frodo takes place far in advance of most of the story. Most of the action happens over the course of 3 years.
The long answer is distilled from this extremely thorough chronology, here's a rundown. All events take place during the Third Age. Let me know what events you'd like me to add.
- 3001 - Bilbo Baggins turns 111. He announces his plan to leave The Shire and does so. Left behind, on purpose, is The One Ring. Frodo and Merry find the ring amongst Bilbo's possessions. Sometime late this year Gandalf suspects that Bilbo's ring is The One Ring.
- 3004-3008 - Gandalf visits Frodo periodically, presumably to keep his eye on the new Ringbearer.
- 3017 - Gollum is captured by Sauron's forces. He's tortured for information on The Ring.
- Aragorn captures Gollum and turns him over to King Thranduil of Mirkwood. He's held there, and questioned by Gandalf, who then leaves for the Shire.
- Gandalf visits Frodo, and determines the ring is The One Ring. This begins the quest, Frodo and Sam make plans to depart. A few months later, they depart with Pippin joining them.
- Orcs attack Mirkwood, Gollum escapes.
- Merry joins the group.
- The hobbits arrive in Bree at the Prancing Pony. They meet up with Aragorn.
- Aragorn and the hobbits arrive in Rivendell. At the end of the year, the Fellowship of the Ring is formed and departs Rivendell.
- They fail to cross the mountains via the pass of Caradhras, so they travel through Moria. Gollum starts following the Fellowship. In Moria, they are attacked by Orcs and a Balrog. Gandalf is separated from the rest of the Fellowship while battling a Balrog.
- The Fellowship goes to Lothlorien. There they meet Galadriel, and receive gifts. They depart down the great river Anduin.
- The Breaking of the Fellowship:
- Boromir attempts to steal the ring.
- Sam and Frodo head to Mordor.
- The group is attacked by Uruk-hai.
- Boromir dies in battle defending Merry and Pippin. They are abducted, and taken towards Isengard.
- Aragorn, Legolas, and Gimli put Boromir into a funeral boat and follow the Uruk-hai who have Merry and Pippin.
- The Uruk-hai are attacked by the Rohirrim. Merry and Pippin escape and meet Treebeard and the Ents.
- Aragorn, Legolas, and Gimli meet Gandalf, who is now 30% whiter. They head to Edoras. Then they head to Helm's Deep, and the Battle of Helm's Deep happens. Gandalf splits off prior to Helm's Deep and heads to Isengard.
- The Ents attack Isengard.
- Gandalf arrives at Isengard, and meets Merry, Pippin, and the Ents. Gandalf heads to Helm's Deep with backup of men and Huorns (ancient and powerful tree-like beings). They arrive at Helm's Deep and contribute to the victory. Gandalf, Aragorn, Legolas, Gimli, King Theoden and his company go to Isengard to meet Saruman. Saruman is imprisoned.
- Gollum joins Frodo and Sam. They head to the Black Gate, then instead head to Minas Morgul.
- Pippin uses the Palantir, and is revealed to Sauron. Sauron mistakes him for the Ringbearer. Pippin and Gandalf head to Edoras, then onwards to Gondor. Merry swears fealty to Theoden.
- Theoden's men gather at Dunharrow. Aragorn, Legolas, and Gimli take the Paths of the Dead.
- Sam and Frodo are captured by Faramir's men. They are brought to Faramir, but he releases them, and they head to the path near Minas Morgul. They sneak in to Mordor, and make their way towards Mount Doom.
- Aragorn, Legolas, and Gimli emerge from the Paths of the Dead, and start working their way towards Gondor, while defeating some of the backup for Sauron's forces.
- In Minas Tirith, Pippin swears fealty to Denethor.
- The Battle of Pelennor Fields
- Sauron's forces attack Minas Tirith.
- Gandalf and the forces in Minas Tirith defend the siege.
- Pippin and Gandalf save Faramir from Denethor's madness.
- The Rohirrim, including Merry, attack Sauron's forces.
- Aragorn, Legolas, Gimli, and the dead join the battle.
- Aragorn heals a ton of people. Then the plan is formed to keep Sauron distracted from Frodo and Sam's progress. He, Gandalf, Legolas, Gimli, Pippin, and a host of others head to the Black Gate and meet the Mouth of Sauron and reject his terms. They then battle Sauron's forces.
- Frodo and Gollum destroy The One Ring in Mount Doom. Frodo and Sam are rescued by Gandalf and the Great Eagles.
- Everyone returns to Minas Tirith.
- Aragorn is crowned King. There was much rejoicing.
- Frodo, Sam, Merry, and Pippin head home. Saruman gets to the Shire first, and sets up shop in Bag End. He enslaves the hobbits, and waits for Frodo, Sam, Merry, and Pippin to return. They arrive and battle with Saruman, who is in the end betrayed by Wormtongue. Wormtongue in turn is killed by the hobbit forces.
- 3021 - Frodo and Bilbo depart for the Grey Havens. Gandalf and many elves go with them. Sam, Merry, and Pippin see them off.
See also The Lord of the Rings Wikia for more information on the names and places herein.