Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do we determine whether a size is base on 1000 or 1024 when we see kb or mb

There are many programs in Linux which would show the size of a file, some of them show it in blocks, some are in bytes. But when it comes to some human readable form, like ls -sh, lvs, dd bs=size and so many, how do we decide if it's a multiple of 1024 or 1000 when we see a kb, KB, mB, MB, K, G etc. Some distinguish them with capitalization like lvs, some with different characters like dd, however, is there a general rule of these kinds of things cause I can't find it so far. Thanks.

like image 253
dspjm Avatar asked Jul 26 '13 03:07

dspjm


People also ask

Is KB 1024 or 1000 bytes?

Based on this, 1 kilobyte is equal to 1000 bytes. Its international symbol is kB. In computer technologies, a kilobyte is specified as 1024 (210). This is because the binary system is widely used in file management systems.

Why 1 KB is 1024 and not 1000?

Remember: Computers can only work with binary code. However computers do like the number 1024 because its binary code is 10000000000. That's why there are 1024 Bytes in a KB, 1024 KB in a MB and so on…

How do you determine KB size?

Right-click the file and click Properties. The image below shows that you can determine the size of the file or files you have highlighted from in the file properties window. In this example, the chrome. jpg file is 18.5 KB (19,032 bytes), and that the size on disk is 20.0 KB (20,480 bytes).

Is 1 MB 1000 KB or 1024 KB?

In digital units of measurement, 1 MB is equal to 1024 Kilo Bytes or KB.


1 Answers

If you look at man units, you'll see a description of the two types of units. Decimal and Binary. Decimal units like Kilobyte (KB) and Megabyte (MB) are in multiples of 1000 (10^3) while Binary units like Kibibyte (KiB) and Mebibyte (MiB) are in multiples of 1024 (2^10).

If the unit being displayed includes a binary prefix like KiB, MiB, GiB, you can be certain it's 1024. For unclear units, a general thumb rule:

  • Hard Drive sizes are advertised in Decimal units, because the manufacturers like to make them look bigger. Accordingly, the size of files stored on the disk and transferred over networks are typically consistent with this.
  • Memory sizes are advertised in Binary units
  • Anything not data related (frequency in KHz, etc.) is always Decimal

Ubuntu published a policy in 2010 for their units which appears to be reasonably consistent across Linux distributions, although not guaranteed:

  • Use base-10 for:

    • network bandwidth (for example, 6 Mbit/s or 50 kB/s)
    • disk sizes (for example, 500 GB hard drive or 4.7 GB DVD)
  • Use base-2 for:

    • RAM sizes (for example, 2 GiB RAM)

For file sizes there are two possibilities:

  • Show both, base-10 and base-2 (in this order). An example is the Linux kernel: "2930277168 512-byte hardware sectors: (1.50 TB/1.36 TiB)"
  • Only show base-10, or give the user the opportunity to decide between base-10 and base-2 (the default must be base-10).1

1 As noted by Kris Avi in a comment, some command-line tools developed before this policy may use only base-2 values but indicate decimal units, and may not have changed in order to avoid breaking existing parsing scripts.

like image 77
Daniel Widdis Avatar answered Sep 30 '22 20:09

Daniel Widdis