Let's get the most obvious out of the way first. Wish.
State your wish to the GM as precisely as possible. The GM has great latitude in ruling what occurs in such an instance; the greater the wish, the greater the likelihood that something goes wrong.
"I wish to be immortal." would be the simplest way. A somewhat better way would be "I wish to cease aging (or be unable to die) until such time as I, of my own free will and under no duress, want this effect to end". That gives the DM fewer ways to monkey's paw your wish and gives you an out.
Class Features
First up we have the Druid.
At 18th level you get the Timeless Body feature which states
Starting at 18th level, the primal magic that you wield causes you to age more slowly. For every 10 years that pass, your body ages only 1 year.
which effectively increases your lifespan by 10 times.
Then there's the Monk class.
You get Timeless Body at 15th level but it's different than the Druid's. It states
At 15th level, your ki sustains you so that you suffer none of the frailty of old age, and you can’t be aged magically. You can still die of old age, however. In addition, you no longer need food or water."
while it doesn't explicitly grant immortality it might still help.
Paladin's Oath of the Ancients has a similar effect to the Monk.
At level 15 you get the Undying Sentinel feature which states
Additionally, you suffer none of the drawbacks of old age, and you can’t be aged magically.
which is similar to the Monk's feature
Warlocks with the Undying patron get a similar benefit to the Druid at level 10.
This is the Undying Nature feature which states
In addition, you age at a slower rate. For every 10 years that pass, your body ages only 1 year, and you are immune to being magically aged."
Wild Magic Sorcerers can age themselves down with wild magic.
Though it's a bit unpredictable and you may get older instead. On the Wild Magic table it says
35–36: Roll a d10. Your age changes by a number of years equal to the roll. If the roll is odd, you get younger (minimum 1 year old). If the roll is even, you get older."
Magic Items
The Ring of Winter has an effect called Frozen Time which states.
As long as you wear the ring, you don’t age naturally. This effect is similar to suspended animation, in that your age doesn’t catch up to you once the ring is removed.
There's also the Potion of Longevity. There's a bit of risk with this one if you drink it more than once and you'll never be able to drink it more than 9 times but here's what it says.
When you drink this potion, your physical age is reduced by 1d6 + 6 years, to a minimum of 13 years. Each time you subsequently drink a potion of longevity, there is a 10 percent cumulative chance that you instead age by 1d6 +6 years.
Boon of Immortality
You stop aging. You are immune to any effect that would age you, and you can’t die from old age.
of course this requires level 20 but it is an option.
Spells (other than wish)
Disclaimer: This was partly taken from Rubiksmoose's answer but I wanted to add details about how it could work.
The Clone spell would let you create a new body for yourself and, as seen here, would allow you to resurrect yourself into your clone body after dying of any means including old age. By default you need to be a Wizard with access to 8th level spells to do it and even then, it's extremely costly as you need a diamond worth at least 1,000 gold pieces as well as a chunk of your flesh. You also would need a vessel worth at least 2,000 gold pieces that has a sealable lid and is large enough to hold a Medium creature such as, for example, an expensive coffin. There's also the fact that it must remain undisturbed for the whole time until you die. There are a few potential methods you could use to get around parts of this.
- The part where it must remain undisturbed is fairly simple to get around. You're a high level wizard with 8th level spells at your fingertips. Cast Demiplane and have the clone grow in there the only catch being you need a way to get out of the Demiplane.
- This is kind of cheating since I did say "other than wish" but what I meant by that was other a stressful wish. You can bypass the material component requirements and the requirement of being a Wizard by using Wish to replicate the effects of Clone. Now for this to work I would assume you'd either still need some sort of vessel or the Wish spell would create it but that's beside the point. The only downside to this is that you do need a 9th level spell slot AND you need to be able to use the Wish spell. Or you could always have a magic item or something that can grant you wishes in which case pretty much anybody could use this to become effectively immortal.