Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

One character in a file “weighs” one byte

by Roy Revelt   ·   posted on Thursday, 18 August 2022   ·   meta

Few people asked me how I count, how much is any arbitrary text “worth” in kilobytes, how I calculate that in my web apps. The answer is simple.


One character in a file “weighs” one byte.

While a kilo-meter is a thousand metres, a kilo-byte is 1024 bytes.

From there, one megabyte equals 1024 kilobytes and so on.

Funny, there’s no mega-meter, but we have a nano-meter.

Back on the subject, here’s a proof — create an HTML file with six characters, then check the file’s size:

Fig 1. On macOS, six-character-long HTML file weighs 6 bytes
Fig 1. On macOS, six-character-long HTML file weighs 6 bytes

That’s how I convert the string length into file size in GUI apps, like here:

Fig 2. email-comb playground estimating file size from a string length
Fig 2. email-comb playground estimating file size from a string length

↑ back to top
older newer

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab