Question: I am creating a BitSet with a fixed number of bits.
In this case the length of my String holding the binary representation is 508 characters long.

So I create BitSet the following way:

```
BitSet bs = new BitSet(binary.length());
// binary.length() = 508

```

But looking at the size of bs I always get a size of 512. I can see that there are always 4 Bits with value of 0 appended at the end.

Maybe there is some misunderstanding of the following documentation:

> 
> **BitSet(int nbits)**
> 
> 
> Creates a bit set whose initial size is large enough to explicitly represent bits with indices in the range 0 through nbits-1.
> 
> 
> 

Is it that BitSet always enhances its size so that its size is powers of 2 or why is it larger?

Answer: 
According to [the documentation](http://docs.oracle.com/javase/7/docs/api/java/util/BitSet.html), the actual size in memory is implementation dependent, so you can't really know for sure what `size()` you're going to get. You as a user shouldn't have to worry about it, though, because the `length()` of the BitSet is always accurate - even if the size in memory is larger, it returns the number of bits actually in use.

Since the BitSet can automatically grow to accomodate any data added to it, I wouldn't be surprised if it uses a growth strategy that's similar to lists, which tend to use increasing powers of two. But as said, that fact is an implementation detail, and it might not be the same everywhere and every time.
The BitSet size will be set to the first multiple of 64 that is equal to or greater than the number you use for 'size'. If you specify a 'size' of 508, you will get a BitSet with an actual size of 512, which is the next highest multiple of 64.