title: How unique are the first 8-12 characters of SHA256 hashes?
body: <p>Take this hash for example:</p>
  
  <pre><code>ba7816bf 8f01cfea 414140de 5dae2223 b00361a3 96177a9c b410ff61 f20015ad
  </code></pre>
  
  <p>It's too long for my purposes so I intend to use a small chunk from it, such as:</p>
  
  <pre><code>ba7816bf8f01
  ba7816bf
  </code></pre>
  
  <p>Or similar. My intended use case:</p>
  
  <ul>
  <li>Video gallery on a website, represented by thumbnails. They are in random order.</li>
  <li>They play in the lightbox. They don't have a unique ID, only their URL is unique.</li>
  <li>While the lightbox is open I add something to the end of the page URL with <a href="https://developer.mozilla.org/en-US/docs/Web/API/History" rel="noreferrer">JS History API</a>.</li>
  </ul>
  
  <blockquote>
    <p>//example.com/video-gallery/<strong>lightbox/ba7816bf8f01</strong></p>
  </blockquote>
  
  <ul>
  <li>The suffix needs to be short and simple, definitely not a URL.</li>
  <li>People share the URL.</li>
  <li>The server can make sense of the lightbox/ba7816bf8f01 in relation to /video-gallery.</li>
  <li>Visiting the URL, the lightbox needs to find which video the suffix belongs to and play it.</li>
  </ul>
  
  <p>I thought I'd SHA256 the URL of the video, use the first few characters as an ad-hoc ID. <strong>How many characters should I use</strong> from the generated hash, to considerably reduce the chance of collision?</p>
  
  <p>I got the idea from <a href="https://developers.google.com/safe-browsing/v4/urls-hashing" rel="noreferrer">URLs and Hashing by Google</a>.</p>