143

I've seen three ways of doing conversion from bytes to megabytes:

  1. megabytes=bytes/1000000
  2. megabytes=bytes/1024/1024
  3. megabytes=bytes/1024/1000

Ok, I think #3 is totally wrong but I have seen it. I think #2 is right, but I am looking for some respected authority (like W3C, ISO, NIST, etc) to clarify which megabyte is a true megabyte. Can anyone cite a source that explicitly explains how this calculation is done?

Bonus question: if #2 is a megabyte what are #1 and #3 called?

BTW: Hard drive manufacturers don't count as authorities on this one!

James A Mohler
  • 11,060
  • 15
  • 46
  • 72
User1
  • 39,458
  • 69
  • 187
  • 265
  • 4
    Hard drive manufacturers **do** count as authorities on this one, insofar as their usage of megabyte to mean sense #1 is driving acceptance of that conversion. Note that Microsoft OSs still use sense #2, though. – Michael Petrotta Mar 02 '10 at 17:17
  • Marketing "engineers" and other folks who can't really compute will divide the number of bytes by a million and call that "MB". Those who know what a MB really is will divide by 2 to the power of 20 (1024 * 1024) and that's the **real** megabyte. – marc_s Mar 02 '10 at 17:39
  • @marc_s: Marketing engineers that know who sign their paychecks will do whatever arithmetic produces a more impressive number relative to their competitors. Only Plato knows what a "real" megabyte is. – Michael Petrotta Mar 02 '10 at 17:43
  • 5
    #3 *should* be called a floppy megabyte. 3½ inch floppies were fairly notable for using this (and I don't recall seeing it anywhere else). – Michael Madsen Mar 02 '10 at 17:48
  • 20
    And the obligatory: http://xkcd.com/394/ – Seva Alekseyev Mar 02 '10 at 17:54
  • 5
    Man oh man. Between this and text encoding, I sometimes despair at our unerring ability to add complicating kinks to the most basic things. – Paul D. Waite Mar 02 '10 at 18:01
  • Leave it to Marketing to screw up what the rest of us would consider "the most basic things" – Neil N Mar 02 '10 at 18:21
  • I am extremely surprised and concerned at the number of people who think hard drive manufacturers should count as authorities. They definitely have a lot of marketing hype to confuse people but that doesn't make them an authority. It just makes them have a conflict of interest. – User1 Mar 04 '10 at 13:12
  • 4
    Hard drive manufacturers most likely use #1 to get the highest number. For GB the difference is 7% and for TB the difference is 10%. – Peter Mortensen Apr 12 '10 at 23:15
  • 2
    Hard drive manufacturers use #1 because they're engineers. The prefix mega- means 1,000,000 and always has. They've been doing it [since before the discrepancy could have made any marketing difference](https://en.wikipedia.org/wiki/Timeline_of_binary_prefixes). In fact, the 1024×1024 convention was invented by marketing types [because customers didn't understand why 32 + 32 = 65](http://www.scribd.com/doc/91459783/Go-to-Harmful#page=4). – endolith Jul 15 '12 at 05:21
  • 1
    The definition depends on if you are counting in binary or decimal: http://en.wikipedia.org/wiki/Orders_of_magnitude_%28data%29 – Cypher Jul 22 '14 at 17:06

10 Answers10

135

Traditionally by megabyte we mean your second option -- 1 megabyte = 220 bytes. But it is not correct actually because mega means 1 000 000. There is a new standard name for 220 bytes, it is mebibyte (http://en.wikipedia.org/wiki/Mebibyte) and it gathers popularity.

Cory Petosky
  • 12,458
  • 3
  • 39
  • 44
Andrey
  • 59,039
  • 12
  • 119
  • 163
  • What? "We mean 2nd"? That does not make any sort of sense. – Matt Ball Mar 02 '10 at 17:14
  • @Bears: Andrey is referring to #2 in the OP's terms - the 1024^2 bytes version. – Cascabel Mar 02 '10 at 17:19
  • 17
    I agree with all this, except the implication that it is gathering a lot of popularity. The mindshare of 1024=K and friends is effectively invulnerable. When you get people to start saying "cracker" instead of "hacker", get back to me. – T.E.D. Mar 02 '10 at 17:29
  • 12
    Not going to downvote for the heretical "mebibyte" mention, but it's taking a lot of effort. – aehiilrs Mar 02 '10 at 17:31
  • 3
    @T.E.D.: actually, the use of "hacker" to mean "cracker" is a perfect example of popular culture overriding the usage that geeks would prefer. – Michael Petrotta Mar 02 '10 at 17:34
  • 3
    it was my personal feeling that mebibyte is gathering popularity, may be i am wrong. i saw on some rather popular download site size shown in MiB and KiB. – Andrey Mar 02 '10 at 17:43
  • 1
    Well, I agree with you and I also use 10-base mega and 2-base kibi and mebi. That is the IEC standard for metric use: that is final and there is no use kicking over it. – Zan Lynx Aug 12 '10 at 18:27
  • 1
    12 years on, general people haven't even heard of this, and most developers still use `megabyte` when referring to binary mebi. Because, reinventing the wheel is blasphemy, and inherently only meant to convolute something. We already had it's type (binary vs decimal, and that was fine). This is a great example why I got out of the tech field beyond personal gratification. Nothing be shenanigans. Just my opinion. – WASasquatch Sep 04 '22 at 06:12
33

There's an IEC standard that distinguishes the terms, e.g. Mebibyte = 1024^2 bytes but Megabyte = 1000^2 (in order to be compatible to SI units like kilograms where k/M/... means 1000/1000000). Actually most people in the IT area will prefer Megabyte = 1024^2 and hard disk manufacturers will prefer Megabyte = 1000^2 (because hard disk sizes will sound bigger than they are).

As a matter of fact, most people are confused by the IEC standard (multiplier 1000) and the traditional meaning (multiplier 1024). In general you shouldn't make assumptions on what people mean. For example, 128 kBit/s for MP3s usually means 128000 bits because the multiplier 1000 is mostly used with the unit bits. But often people then call 2048 kBit/s equal to 2 MBit/s - confusing eh?

So as a general rule, don't trust bit/byte units at all ;)

AndiDog
  • 68,631
  • 21
  • 159
  • 205
25

Divide by 2 to the power of 20, (1024*1024) bytes = 1 megabyte

1024*1024 = 1,048,576   
2^20 = 1,048,576
1,048,576/1,048,576 = 1  

It is the same thing.

Palash Ahuja
  • 522
  • 1
  • 5
  • 15
Marie
  • 251
  • 3
  • 2
21

BTW: Hard drive manufacturers don't count as authorities on this one!

Oh, yes they do (and the definition they assume from the S.I. is the correct one). On a related issue, see this post on CodingHorror.

Federico A. Ramponi
  • 46,145
  • 29
  • 109
  • 133
  • 5
    Sorry downvoter, but their definition of Mega *IS* the correct one, no matter what programmers think. I can live with M = 2^20, fine, but that is just for historical reasons. – Federico A. Ramponi Mar 02 '10 at 22:15
  • 1
    +1 for the moxie of standing with the HD companies and SI standards enthusists against everyone else! – Jeffrey L Whitledge Mar 02 '10 at 22:32
  • 13
    Thanks Jeffrey :), but it's not just the HD companies: Your CPU does 2600 MHz; Your math processor does XY Mflops; Ethernet does 100 Mbit/s; Your camera does 5 Mpixel; Blu-ray's 1x speed is 36 Mbit/s... All these "M" stand for 10^6, not 2^20. – Federico A. Ramponi Mar 02 '10 at 22:57
  • -1 I'm not sure I follow this answer. Which hard drive manufacturer *made* a definition? I don't think CodingHorror produces hard drives? I'm looking for an authority and a hard drive manufacturer would have too much bias to be objective. – User1 Mar 03 '10 at 20:55
  • 1
    The "authority" supporting M=10^6 is the International Bureau of Weights and Measures. As far as I know, there is no "authority", besides custom, supporting M=2^20. – Federico A. Ramponi Mar 03 '10 at 22:32
  • http://stackoverflow.com/questions/234075/what-is-your-best-programmer-joke/237814#237814 – Federico A. Ramponi Mar 10 '10 at 22:54
  • I'm not gonna downvote, but I'd point out that SI is kinda irrelevant in this case, because "megabyte" is technical jargon, and is conventional to the specific areas of computer science and engineering. If you want to cite IEC or other standards which adopt the SI definition purely for convenience or compatibility reasons, that's reasonable, though other standards may disagree. But the point is that "megabyte" will never equal 10^6 bytes simply because that's what SI says "mega", etc. means. – Ionoclast Brigham May 12 '16 at 19:11
  • @IonoclastBrigham If you read the other answers, the IEC standard IS that mega means 10^6, not 2^20. They specifically have a different designation for that; mebi. So by all standards (not just what we colloquially call them) a Megabyte is 10^6 bytes and a Mebibyte is 2^20. – Justin May 17 '18 at 13:04
7

for convert byte to megabyte(MB)

use totalbyte/1000/1000

for convert byte to mebibyte (MiB)

use totalbyte/1024/1024

https://en.wikipedia.org/wiki/Byte#Multiple-byte_units

Piotr Kula
  • 9,597
  • 8
  • 59
  • 85
harun_me
  • 111
  • 1
  • 4
4

The answer is that #1 is technically correct based on the real meaning of the Mega prefix, however (and in life there is always a however) the math for that doesn't come out so nice in base 2, which is how computers count, so #2 is what people really use.

Grant Johnson
  • 1,224
  • 10
  • 12
2

Megabyte means 2^20 bytes. I know that technically that doesn't mesh with the SI units, and that some folks have come up with a new terminology to mean 2^20. None of that matters. Efforts to change the language to "clarify" things are doomed to failure.

Hard-drive manufacturers use it to mean 1,000,000 bytes, because that's what it means in SI so they figure technically they aren't lying (while actually they are). That falls under lies, damn lies, and marketing.

T.E.D.
  • 44,016
  • 10
  • 73
  • 134
2

Use the computation your users will most likely expect. Do your users care to know how many actual bytes are on a disk or in memory or whatever, or do they only care about usable space? The answer to that question will tell you which calculation makes the most sense.

This isn't a precision question as much as it is a usability question. Provide the calculation that is most useful to your users.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
1

In general, it's wrong to use decimal SI prefixes (e.g. kilo, mega) when referring to binary data sizes (except in casual usage). It's ambiguous and causes confusion. To be precise you can use binary prefixes (e.g. 1 mebibyte = 1 MiB = 1024 kibibytes = 2^20 bytes). When someone else uses decimal SI prefixes for binary data you need to get more information before you can know what is meant.

0

Microsoft Windows Explorer shows file size in the "Properties" window. This is a conversion from the byte count using 2^20

Phil
  • 1