Well actually there are 1024 bytes in a kb and kb in a mb etc. So this is actually 35.39Gb. I think memory is lost in the filing system, which allows searching, directories, file permissions etc. You'll never get quite as much as the disk can provide for your own files.
First of all, the 40GB you've quoted is a decimal value. Computers count in binary, 0's and 1's, and so where as in decimal 1GB = 1000MB, in binary 1GiB = 1024MiB.
If you divide 40000 by 1024, you'll get 39GiB.
The other stuff can be accounted for as mikey says: the file system itself takes up a small amount of room (different depending on the filesystem in use).