After Matthew Mellon, scion of the Mellon banking fortune, died on April 16 of a drug-related heart attack in Mexico, his family was unable to locate the pass code needed to retrieve his fortune — said to have been worth as much as $1 billion — in XRP cryptocurrency, according to the Daily Mail.

Losing passwords is the kind of nightmare that haunts bitcoin investors. In fact, there are an estimated 3 million bitcoins — totaling nearly $25 billion — lost because the retrieval codes have gone missing or the currency owners died without passing the codes onto their next of kin.

Just ask James Howells — who lost a hard drive with the key to more than $60 million in bitcoin.

“I mined more than 7,500 coins over one week’s time in 2009; there were just six of us doing it at the time, and it was like the early days of a gold rush,” said the IT worker turned crypto investor, 32, who lives in Newport, Wales.

“Four years later, I had two hard drives in a desk drawer. One was empty and the other contained my bitcoin private keys,” Howells recalled. “I meant to throw away the empty drive — and I accidentally threw away the one with the bitcoin information.”

In 2008, bitcoin’s alleged creator Satoshi Nakamoto published an open-source code through which bitcoins are “mined” by solving complex calculations, embedded throughout the Internet, via extremely powerful computers. There is a finite number of 21 million bitcoins.

Part of cryptocurrency’s appeal is that it’s anonymous, untraceable and can only be retrieved by the person with the private key. Randomly generated by the Bitcoin algorithm, these can be more than 50 characters long — not exactly something you can memorize.

“People put them on laptops, storage drives, USBs,” said Brian Stoeckert, a legal consultant in the crypto field. “Lose one of them without having it backed up, and you are out of luck.”

Howells didn’t realize the value of his coins for a few weeks after he lost them. “I looked up the price, did the calculation . . . and thought, ‘S - - t. [My investment is] worth around $2 [million] or $3 million.’ A few months later it was worth $9.9 million. I was annoyed, pissed off, sick. I spoke to the people at the landfill and told them that I threw away a hard drive worth $10 million. They looked at me stupidly.”

His story echoes a plotline in the recently wrapped season of the HBO show “Silicon Valley,” where blowhard venture capitalist Russ Hanneman, played by Chris Diamantopoulos, is seen leading a crew of hired trash pickers at the local dump, on a mission to turn up a mistakenly discarded thumb drive that contained the code needed to retrieve his $300 million in bitcoin.

“We heard a lot of stories about people having incredibly long numbers [as their pass codes, known as private keys] and losing them,” series creator Mike Judge told The Post. “There’s definitely a part of the tech culture, Silicon Valley in particular, where people take pride in failure. But I don’t think losing a hard drive with your Bitcoin code on it falls into that category. I think it happens more than people want to admit.”

Atlanta-based software developer Syl Turner, 33, can relate. After mining two bitcoins in 2010, he didn’t give much thought to the cryptocurrency and ended up moving the computer to his attic when he bought a new one.

Then, “last November, [the value of a bitcoin] hit $10,000. Everybody was talking about bitcoin, and it seemed like I should go into the attic to find the computer,” he said.

He found what he was looking for but had inadvertently written over the hard drive — erasing his private key. “I’m pretty sure I wrote over it because bitcoin had no real monetary value at the time I did it,” Turner said.

So why don’t more people keep better track of their magic numbers? “It’s problematic in that if you have your code written down in too many places, people can find it and take your money,” said Judge. “But if it’s in too few places, you may not be able to find it yourself.”

Which can become a nightmare when investors pass away without having shared their private keys with their heirs.

According to Michael Yang, who runs a cryptocurrency exchange in the Bay Area, “One of my friends had half of a bitcoin private key in his hand and half in his [business] partner’s hand. Then the partner passed away.” Now, the living friend cannot access the funds.

“It’s a tragedy,” Yang added. “They had at least 500 bitcoins” — worth around $4 million. (A source close to Mellon’s family, meanwhile, denied they were unable to locate his money.)

Some believe that bitcoin’s mysterious creator, Nakamoto, may have lost his private key. (Another theory is that he committed suicide and failed to leave the pass code behind.)

“None of the [1 million] coins he mined have moved,” said Kim Grauer, senior economist with Chainalysis, a Manhattan-based digital forensics firm. “It’s odd that they have not been cashed out.”

If an investor remembers at least a portion of a pass code, a talented hacker could potentially use software to decrypt it. For someone like Howells, however, who has no clues to go on, “hacking it would take a couple billion years and require all the energy of the sun.”

Instead, he’s offered the town of Newport 10 percent of the bitcoins’ value if they’ll let him excavate the landfill. So far, they’ve denied his requests.

For the time being, Howells views the dump as the ultimate safe. “Nobody else can get in there and take my hard drive,” he said. “It’s like having $75 million in the bank, but you cannot get into the bank account.”

Turner, however, has learned his lesson and is done.

“I have no crypto now and have little desire to get more,” he said. “Some [aspects] of it are fascinating. But it also seems like a cult.”