Skip to main content

The context you need, when you need it

When news breaks, you need to understand what actually matters — and what to do about it. At Vox, our mission to help you make sense of the world has never been more vital. But we can’t do it on our own.

We rely on readers like you to fund our journalism. Will you support our work and become a Vox Member today?

Join now

Gangnam Style got so many views that it nearly broke YouTube

Marco Del Grande/The Sydney Morning Herald/Fairfax Media

The video for Psy’s song “Gangnam Style” is the most-viewed video in the history of YouTube, with more than 2 billion views. And that created some headaches for Google’s engineers. Because it stores numbers in binary, YouTube was only designed to record up to 2,147,483,647 video views. Without a software upgrade, the “Gangnam Style” counter would have begun showing the song getting negative 2.1 billion views.

Why is the limit such a goofy number? And what did YouTube have to do to fix the glitch? Read on to find out.

Why was there a limit to the number of views YouTube could count?

Psy, the man behind "Gangnam Style." (OZAN KOSE/AFP/Getty Images)

To understand YouTube’s Gangnam Style problem, you have to understand how computers count. Human beings count using the decimal number system. As we all learned in grade school, you count 1, 2, 3, get to 9, then “roll over” to 10 and count 11, 12, 13, and so forth.

Computers do things differently from humans in two important ways. First, they use the binary number system, which has two possible values — 0 and 1 — instead of 10. Decimal 1 is binary 1, then decimal 2 is binary 10, decimal 3 is binary 11, decimal 4 is binary 100, and so forth.

Second, when humans write a number like 19, we write however many digits are necessary to represent the number — in this case, the two digits 1 and 9. But computers are storing numbers in electronic circuits with a fixed number of digits. So when they represent a number like 10011 (19 in binary), they pad it out with 0s on the right-hand side. One of the most popular ways to store numbers digitally is with a 32-bit binary number. In this format, decimal 19 would be stored as:

00000000000000000000000000010011

This works great as long as your software is only handling numbers that fit into this format. But weird things happen if computers are asked to handle a number so large that it doesn’t fit into the space that was set aside for it. That’s what happened in this case: the number of Gangnam Style views was so large that it could no longer fit into the space Google had set aside for it.

If YouTube was storing 32 binary digits, then it should be able to count up to 2^32 = 4,294,967,296. But the counter broke at 2,147,483,647. How come?

(Rob Brooks)

You can use 32 bits to represent any number from 0 to 4,294,967,295. But this has a big disadvantage: you can’t represent negative numbers. So computers often set aside the left-most digit to represent a number’s sign (0=positive, 1=negative), leaving 31 digits to represent the number itself.

That’s what Google did in this case, and 2 to the 31st power is 2,147,483,648. So when Psy got his 2,147,483,648’s view, all hell broke loose.

What happens when a number gets too big to fit in the space reserved for it?

The largest positive integer you can represent in this format is:

01111111111111111111111111111111

If you add one to this amount, you get:

10000000000000000000000000000000

The way computers represent negative numbers is too complicated to explain here (Wikipedia has the gory details), but the bottom line is that this counter “wraps around,” going from the highest number that can be represented in this format — 2,147,483,647 — to the lowest: negative 2,147,483,648.

There’s a funny xkcd cartoon about this:

So when Psy got his 2,147,483,648th view, YouTube’s server would have thought he had minus 2,147,483,648 views.

How could YouTube fix the problem?

YouTube didn’t explain how it fixed the problem in any detail, but one fix is fairly easy: YouTube just had to treat the number as an unsigned integer, treating the left-most digit as part of the number rather than as a minus sign. If you hover over the play count on the Gangnam style video, it first shows the video having -2.1 billion views, then the numbers spin until they show the correct figure.

However, this strategy will only work for another 2 billion views or so. When Psy gets his 4,294,967,296th view, a 32-bit counter will roll over from

11111111111111111111111111111111

to

00000000000000000000000000000000

The system will think he has zero views.

A longer-term fix would be to start using a larger number of bits — most likely 64 — to represent view counts. Then YouTube will be fine until someone gets 2 to the 63rd power views — a number so huge that no video could possibly reach it.

More in Technology

Technology
The case for AI realismThe case for AI realism
Technology

AI isn’t going to be the end of the world — no matter what this documentary sometimes argues.

By Shayna Korol
Politics
OpenAI’s oddly socialist, wildly hypocritical new economic agendaOpenAI’s oddly socialist, wildly hypocritical new economic agenda
Politics

The AI company released a set of highly progressive policy ideas. There’s just one small problem.

By Eric Levitz
Future Perfect
Human bodies aren’t ready to travel to Mars. Space medicine can help.Human bodies aren’t ready to travel to Mars. Space medicine can help.
Future Perfect

Protecting astronauts in space — and maybe even Mars — will help transform health on Earth.

By Shayna Korol
Podcasts
The importance of space toilets, explainedThe importance of space toilets, explained
Podcast
Podcasts

Houston, we have a plumbing problem.

By Peter Balonon-Rosen and Sean Rameswaram
Technology
What happened when they installed ChatGPT on a nuclear supercomputerWhat happened when they installed ChatGPT on a nuclear supercomputer
Technology

How they’re using AI at the lab that created the atom bomb.

By Joshua Keating
Future Perfect
Humanity’s return to the moon is a deeply religious missionHumanity’s return to the moon is a deeply religious mission
Future Perfect

Space barons like Jeff Bezos and Elon Musk don’t seem religious. But their quest to colonize outer space is.

By Sigal Samuel