House Speaker Paul D. Ryan's retirement will leave the Wisconsin Republican with a short 38-month reign as speaker, not uncommon in recent years, but it will make him the first speaker to retire while in office in more than 30 years.

Second in line to the presidency and wielding the gavel in the House, the speaker holds one of the nation's most powerful positions — and it has rarely been given up voluntarily. Sam Rayburn (D-Tex.), the record holder for speaker at 17 years, died in office in 1961.

In the 20th century, several speakers held office for long terms. Thomas P. “Tip” O'Neill (D-Mass.) was speaker for a decade before retiring in 1987. He was most famous for going toe-to-toe with Republican President Ronald Reagan when divided government was handled through negotiation more than stalemate.

Ryan will be the first speaker to retire from office since O'Neill.

Every speaker since O'Neill has either resigned or lost power when the other party gained control of the House. The modern political environment has led to shorter terms.

Fifty-four people have served as speaker, 32 of whom served multiple terms.

Joseph Cannon (R-Ill.) was the first new speaker of the 20th century, succeeding David B. Henderson (R-Iowa), who took office in 1899. Cannon remained speaker through four two-year sessions before running unsuccessfully for president.

The next three speakers all lasted at least six years, the last of whom, Nicholas Longworth (R-Ohio), died in office in 1931.

Rayburn served as speaker for 17 years, but not in one long stretch: He served as speaker in three separate terms, twice being succeeded by Republican leader Joseph William Martin Jr. (Mass.).

Rayburn, Cannon, Longworth and O'Neill all have congressional office buildings named after them near the Capitol.

Terms since then have all been shorter.

Resignations ended the shorter terms of Jim Wright (D-Tex.), Newt Gingrich (R-Ga.) and John A. Boehner (R-Ohio). Being voted out of power cut the relatively brief terms of Tom Foley (D-Wash.), J. Dennis Hastert (R-Ill.) and Nancy Pelosi (D-Calif.).