'Is there any possibility that GUID will all be used up?

Given that each GUID is represented by 16 bytes. So at best there are 2^128 possibilities = 3.4028237e+38 possible GUIDs.

Will it be possible that it will all be used up?



Solution 1:[1]

To show you how big 2^128 GUIDs is:

1 GUID = 16 bytes.

Therefore 2^128 GUIDS would need 2^4 * 2^128 bytes to be stored.

2^4 * 2^128 = 2^132 bytes

Using Python, I calculated that this would take:
4,951,760,157,141,521,099,596,496,896 terabytes, or 45 exabytes.

So first you would need to worry about being able to store that many GUIDs, before you could even consider running out of them.

Basically: it is impossible for you to run out.


Collisions

Just because I've heard people worry about collision so many times, I will expand my answer to include an analysis of the possibilities of collisions.

The average number of UUIDs you would need until you get a collision is:

2^(128 / 2) = 2^64

This means that there is a 50% chance that by the time you generate 2^64 UUIDs, you will get a collision. The number of UUIDs you need for this is:

18446744073709551616 UUIDs

This is equivalent to generating 1 billion UUIDs per second for 85 years. The probability to find a duplicate UUID in 103 trillion UUIDs is one in a billion.

Note: This is all assuming the UUIDs are generated with a good algorithm for Randomness and a good source of Entropy.

For more information, see the Birthday Problem and Universally Unique Identifier.

Solution 2:[2]

I would only add that most probably we wouldn't want to arrive to a 1% of having a repeated Guid. Nonetheless for that you would need to have covered 2^121 (2658455991569831745807614120560689152) combinations, in order to have a 0.78125% chance of having a repeated Guid.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Brent
Solution 2 Julio Pereira