A popular chess app inadvertently broke the mathematical limits of older Apple devices

Bad move.
Bad move.
Image: Creative Commons 2.0
We may earn a commission from links on this page.

Two billion, one hundred forty-seven million, four hundred eighty-three thousand, six hundred forty-seven, or 2^31-1. That number meant good news and bad news last weekend for the popular iOS app made by Chess.com. The good news was that it was the number of games users had played on its platform, more than 2.14 billion. The bad news was that the app stopped working for anyone playing on an Apple iPhone or iPad made before mid-2013, because those devices aren’t capable of interpreting such a large integer. When they tried to access a game with an ID higher than that number, the app crashed.

“All of this started happening late on Saturday,” Chess.com CEO Erik Allebest later wrote in a blog post on the site. “Early reports from members were difficult to understand.”

It wasn’t the first time the usage of an app or service outpaced what its developers originally expected. In 2012, Psy’s hit “Gangnam Style” became the first YouTube video to break 1 billion views. In 2014, it broke 2 billion. The number had grown so large that it was literally about to break the YouTube counter itself. If it exceeded 2,147,483,647 views, the number would be higher than Google’s systems had been setup to store.

“We never thought a video would be watched in numbers greater than a 32-bit integer,” YouTube said in a post on Google+ at the end of 2014. “‘Gangnam Style’ has been viewed so many times we had to upgrade to a 64-bit integer (9,223,372,036,854,775,808)!”

YouTube was referring to the way it stores view count numbers in its databases. When setting up a database table to store numbers, it’s not uncommon to tell the database to treat those numbers as 32-bit integers, which max out at 2,147,483,647, a number so high that it can seem a suitable limit, especially when first building an app. After all, to tell the database from the start to accept 64-bit numbers, which include integers up to 9 quintillion, would be a waste of the space that’s allocated for such large numbers, especially when the numbers being stored will often be very small.

If a database setup to handle only 32-bit integers receives a value of more than 2^31-1, it breaks. That was the issue YouTube had to guard against, on the back-end, in databases that stored information about videos on Google’s servers. It wouldn’t necessarily have stopped viewers from watching Psy’s video, but would have caused problems with the view count being displayed beneath it. (When YouTube first posted about the 64-bit upgrade in 2014, there were scattered reports that it was a joke. We checked with Google, and a spokesperson confirmed it was not. “The statement is not a joke,” the spokesperson said in an email. “It’s for real.”)

For Chess.com, the issue manifested on the front-end, in the app itself. If a 32-bit device tries to interpret an integer higher than 2^31-1, it fails. The app must have been making an attempt to store the game ID, which represents the iterative number of games played, as an integer variable. Only 64-bit devices can compute 64-bit integers, and while that kind of data bandwidth became available in PCs and laptops in the mid-2000s, it wasn’t introduced into mobile devices until Apple’s iPhone 5s and iPad Air in 2013.

That means Bill Gates and other multibillionaires would not have been able to record their net worth on the first version of Windows XP, at least not as a regular integer. Of course, developers did find ways for 32-bit computers to handle numbers exceeding 2.14 billion by treating them as data types other than integers. They could be handled sort of like strings of text, for example, and broken apart in background processes to perform large math operations. Otherwise, apps like spreadsheets and calculators would have been extremely limited.

“The moral of the story, I guess, is: When you have an idea, always plan BIG,” wrote Allebest in his blog post. “That’s why when I retire and open my donut shop, I’m going to have seating for THREE billion customers.”

Correction: In a previous version of this article, we wrote 2,147,483,647 as 2^31, but the correct representation is 2^31-1. The article has been updated.