I'm not sure whether I'm asking on the right site, since all the other questions seem to be a lot more abstract and theoretical. If I should remove the question, please tell me.

Are all files on my computer an integer amount of bytes? That is, does every file on my computer consist of an amount of bits divisible by 8? Or are there files that are, for example, 300 bits (37 and a half byte), or 301 bits (37.625 bytes)?

Follow-up question: does this mean that every file can be 'read' using a program that reads ASCII encoded files? (Of course the output would be nonsense, but the program shouldn't notice any difficulties, right?)


Yes, every file has an integer amount of bytes. In fact, most file systems deal with blocks or clusters of bytes. If cluster size is 64KB a file may claim to take up 250KB, but it will actually take 4 clusters or 256KB. This reduces the problem of fragmentaton (now fragments can only get so small, and there can only be so many of them) and the problem of addressing (how big do addresses need to be to access any byte in your 500GB drive? Now the addresses can be shorter by 16 bits).

  • $\begingroup$ Does this mean that if I write a Python script to write a binary file it must write to the hard drive in blocks? Or will the OS take care of it? If so, how? Are 0's added or something to fill up the leftover bytes? $\endgroup$
    – Dasherman
    Nov 30 '14 at 9:23
  • $\begingroup$ @Dasherman, OS will take care of everything. $\endgroup$ Nov 30 '14 at 9:28
  • 1
    $\begingroup$ What @KarolisJuodelė said is true for many, but not all filesystems. E.g. ZFS has variable block size, and ReiserFS can put multiple small files into the same block. Also, filesystem physical organization is separate from the file abstraction per se, so I think this answer is rather misleading. The file abstraction is the open, read, write, seek etc. APIs - all of which simply operate at byte granularity in all implementations I'm aware of (there's no API for writing or reading an amount of data that's not multiple of 1 byte), thus answering your question. $\endgroup$
    – jkff
    Dec 1 '14 at 4:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.