# Are YouTube codes guaranteed to always be 11 characters?

I'm writing code to validate YouTube URLs. Is it guaranteed that the video ID, such as `oHg5SJYRHA0`, is always exactly 11 characters long, or can it sometimes be shorter or longer? Is there any official documentation about this?

-

## migrated from stackoverflow.comMar 26 '11 at 10:36

This question came from our site for professional and enthusiast programmers.

At least until 5.20e+19 videos are made ;) – Jason McCreary Mar 26 '11 at 2:17
@Jason damn you! what calculator are you using! – Saad Mar 26 '11 at 2:23
The max. combination in 11 chars seems like a large number, but it wont't be probably enaugh in a few years since the number of uploaded youtube videos grows exponentialy... So do NOT count on that if you are creating not-for-one-year websites. – jave.web Aug 12 '14 at 16:52
@jave.web You're late to the party. I was asking for authoritative sources, not for someone to argue whether 64^11 is a big number. There could be other reasons that some video codes could be different format than running out of them. For example, there might be legacy videos with shorter codes, or videos that are stored in a separate system, with a different code format entirely. The accepted answer contains the most authoritative answer I've seen so far. – nitro2k01 Aug 15 '14 at 21:51
my comment still applies, especially in 2014, and just supports the accepted answer ;) – jave.web Aug 18 '14 at 21:55

They'll probably stick to 11 chars for a long time. Each character has 64 possible values:

2*26 letters (lowercase and uppercase) + 10 for the digits, + 2 for "_" and "-" chars

``````2 * 26 + 10 + 2 = 64
``````

Then 11 characters in total:

64^11 = 73786976294838210000 (or more or less "73,7e18")

Of course not all combination will be used, depending on their algorithm, but they are probably not going to change it anytime soon. Words from a YouTube developer state that they do not guarantee, though:

I don't see anywhere in the documentation where we officially commit to a standard length of 11 characters for YouTube video ids. It's one of those things where we have a current implementation, and it may stay that way indefinitely. But we're not offering any official commitment to that, so proceed at your own risk.

A better approach, though one that's more involved, would be to take each video id and make a request to the YouTube API to see if it's valid. E.g., make an HTTP GET to

and see if you get back a HTTP 200 response. Of course, if you take that approach, videos that have been removed from YouTube will come back as invalid (which may or may not be what you want) and videos that have been very recently uploaded to YouTube might also come back as invalid.

Cheers, -Jeff Posnick, YouTube API Team

-
@Diego: If you're going to cite so many digits, you may as well show the last few: 64^11 = 2^66 = 73,786,976,294,838,206,464 With 0.5 rounding, the engineering form is 73.787e18 . – user60228 Feb 9 '14 at 21:46
I agree with @user60228, do not show full digits unless you show full accuracy or detail otherwise. Just interesting to some of us to know the full mathematical truth. (P.S. Great answer!) – Xonatron Feb 25 '15 at 21:01

Something worth pointing out, a couple of the URLs point to the same video. For example, in the videos posted below, they are all "The 2015 Nobel Prizes!" by Scishow:

Also, if you change the last character to `C` or `D` that will work too.

-

Yes, they always have 11 characters.

-
Do you have any information to back that up? – Al E. Jun 15 '12 at 13:22