I'm developing an application that displays youtube videos. I want to store the video id's in a database, but because there are going to be a lot of videos, I want to minimize the required space, so does anyone know the maximum length of a video id on youtube?
3 Answers
It's almost certainly going to stay at 11 characters. The individual characters come from a set of 64 possibilities (A-Za-z0-9_-).
64^11 is somewhat more than 2^64. (10 characters would not be enough.) So basically each youtube ID is actually a 64bit number. And I quite doubt they will ever run out of those.
If you want to save space in your database you could theoretically convert the IDs to 64bit numbers then convert them back later. But you would need to know how youtube does the conversion so it's not practical. (Since 64^11 is more than 2^64 you can't store all possibilities, so you need to know which ones are impossible and google doesn't say.)
It takes 66 bits to store all possibilities. So you could actually store a 64bit number plus a 2 bit number and save some space that way. Or more practically store 9 8bit values - you would save only 2 bytes per record though over storing it as text, so it's probably not worth it.

- 25,995
- 5
- 59
- 69
-
5FYI to all those wondering (like me): see Jeffrey's answer (Google API team), there is no commitment by Google regarding this size. https://groups.google.com/forum/?fromgroups=#!topic/youtube-api-gdata/oAztQ3f1tcM – TheZuck Jan 17 '13 at 10:50
-
38@TheZuck I know they didn't commit to it, but I'm comfortable with saying it's not going to change because there is no reason for them to change it: 64 bits is enough for each human on earth to upload 2 billion videos. – Ariel Jan 18 '13 at 10:13
-
15@Ariel I love stats like that. I plan to fill my quota. – andyface Feb 19 '13 at 09:50
-
9@Ariel Your comment is extremely naive and assumes that the only reason to change the video identifier is due to running out of space. There are numerous other factors, and in google's case the biggest likely secondary factor is PAYING CUSTOMERS. I wouldn't be surprised if at some point they allow youtube "partners" to purchase short URL identifiers. When Google says they won't confirm your suspicion, its because they are reserving the right for such changes in the future if desired one day. I'm not saying they will do this, but pointing out that *you can't say they won't*. – BenSwayne Aug 12 '14 at 21:41
-
10@BenSwayne First I never said "they won't", I said "almost certainly". Second I'm not in the slightest worried - if they would change it they would break many sites, which they won't do unless forced, and running out of space is the only thing that would force them, and that's not a concern. If they added premium ID's it would be via a different letter (i.e. not `v=` but something else). – Ariel Aug 13 '14 at 02:16
-
@Ariel that comment made my day. – Alex Coplan Aug 13 '14 at 13:20
-
I don't think you would need to know how Google actually converts from the 64 bit number precisely. I think any scheme you come up with would work fine since you won't be making foreign key references to their internal datastore. All you need to do is make sure you can get to a binary number and back consistently. Also, you could use a single `BINARY(10)` column in MySQL. It would offer pretty much all the benefits of the `BIGINT` without having to define and work with an extra column. – jeteon May 12 '15 at 00:07
-
5I have verified that the algorithm is probably base64 (urlsafe, with -_ as additionnal chars). The last character of the video id is coded on 4 bits instead of 6: there are only 16 possibilities for the last character instead of 64, and they align well with the default base64 urlencoding alphabet. Therefore you can easily encode a youtube id to an (u)int64. The ids do seem random though. – Aissen Jun 24 '15 at 13:37
-
Follow this link.. Its damm clearly explained [Will YouTube Ever Run Out Of Video IDs?](https://www.youtube.com/watch?v=gocwRvLhDf8) – Suresh Velusamy Aug 10 '17 at 14:31
-
12 billion videos should be enough for anybody - famous last words :) – Florian F Oct 13 '18 at 20:00
-
2 billions is a wrong assumption; 64 bits can store up to 18 quintillion different values. 2 billions would be for signed 32 bits. – ranieri Oct 02 '19 at 20:30
-
4@ranisalt It's 2 billion per person, not 2 billion in total. – Ariel Oct 03 '19 at 08:08
-
Quite obviously, if they were as sure as @Ariel is, they would have just committed. So they are not as sure. Why? Because it's nowhere near as certain as Ariel thinks it to be. – szpanczyk Dec 27 '20 at 20:52
-
By the way I only came to point out the same thing @jeteon did - you absolutely don't need to know how they convert back and forth for you to convert back and forth consistently within your own solution. And that's all you need. – szpanczyk Dec 27 '20 at 20:52
-
@Aissen what is actually your rationale for saying they use base64? It would seem to me that if you use that to convert back and forth and you arrive at random numbers, it neither proves nor disproves anything. Is there something I am missing? – szpanczyk Dec 27 '20 at 20:55
The video ID of a YouTube video is currently 11 characters in length. Here are a few links that I found:
http://snipplr.com/view/19232/retrieve-youtube-video-id-from-a-yt-url/
However, while this is the current standard, there is no official stance on how long the video ID can be. Here is a posting to that effect from a team member at YouTube:

- 16,412
- 5
- 39
- 75
I've found this video id jCJ7pHxKlEM1
youtube that has a video id of 12 characters.

- 1,835
- 2
- 18
- 28
-
44Youtube actually crops the video to 11 characters. You can provide the `jCJ7pHxKlEMxxxxxxxxxxxxxxx` and will still get the video with id `jCJ7pHxKlEM`. – Vestalis Feb 09 '17 at 12:45