I have been going through some resources on bootloaders, programmers, etc (I'm very new to this specific subject) and how they work with the Atmega chips and Arduino board programming. My research may have been shallow but none of the online articles/blogs/forum posts that I have been through mentioned that the .hex file (in intel hex ASCII format) needs to be converted to any other kind of binary format. It did seem odd to me though that one would directly write ASCII plain text into an MCU's flash. Also, when using AVR Burn-o-Mat (a GUI front end for avrdude) I did notice a couple of times that the number of bytes being flashed was significantly less than the actual size of the hex file. Most recently I went through this library on github which converts intel hex into a binary format. So am I right in saying that the hex file needs to be converted to binary? So for instance, does avrdude basically do this before sending the binary stream to the bootloader (when uploading a sketch via the IDE)?

  • 1
    I use that library in a sketch which reads hex from SD card and writes it as binary to flash on Arduino Mega. github.com/JAndrassy/ArduinoOTA/blob/master/examples/Advanced/…
    – Juraj
    Jun 20, 2023 at 11:04
  • 1
    If you read the documentation of Avrdude, you will find that it is able to use different formats of the binary to flash, including binary. The command line argument includes the specifier. Jun 21, 2023 at 6:27

1 Answer 1


Yes, the hex codes in the .hex file are read in by avrdude (or other programs) and written to the MCU in binary. A small microprocessor would not be able to read ASCII format commands.

See my answer about What happens when code is uploaded using the bootloader?

(Following on from some comments)

I did notice a couple of times that the number of bytes being flashed was significantly less than the actual size of the hex file

I think there is some confusion here, because of the different way numbers can be represented, or stored. Just for example, the number which we know as "twenty" could be written (in a file) as:

  • 20 (decimal)
  • 00020 (decimal with leading zeroes)
  • 0014 (hex)
  • 0024 (octal)
  • 10100 (binary digits)

Now a program like Avrdude could read numbers in any of those formats, internally convert them to "binary" and send a single byte, being that binary number, to the MCU for placing into a program memory byte.

The .hex format, which the Arduino system produces as part of the compilation process, uses lines in this format:

Line format:
  :      = a colon
  (All of below in hex format)
  nn     = length of data part
  aaaa   = address (eg. where to write data)
  tt     = transaction type
           00 = data
           01 = end of file
           02 = extended segment address (changes high-order byte of the address)
           03 = start segment address *
           04 = linear address *
           05 = start linear address *
  (data) = variable length data
  ss     = sumcheck
            * We don't use these

The above from comments in my file https://github.com/nickgammon/arduino_sketches/blob/master/Atmega_Hex_Uploader/File_Utils.ino

Example: Optiboot in all its glory (only 512 bytes):


So, a line in the .hex file will start with a colon, then a length, then an address, then a transaction type, then some variable amount of data, and then a sumcheck. These are stored in the file in hexadecimal notation.

The very first thing we can deduce from this is that the file size will be over double the amount of memory that is programmed. For example, to program "AB" in hex, this would take two bytes in the .hex file ("A" followed by "B") but these would be converted into the equivalent one-byte "binary" number, which would end up in the MCU memory.

Then, because of the colon, the transaction type, the line length, and the sumcheck, the file will be somewhat longer still, than double the number of bytes to be programmed into the MCU. That is the file layout overhead.

  • "[...] would not be able [...]" is not correct as a general statement. The authors of the bootloader deliberately decided to use only binary data. ;-) You might also want to add that Avrdude is able to read multiple formats of the binary to flash, including binary. Jun 21, 2023 at 6:26
  • I wrote that in the context of the question "It did seem odd to me though that one would directly write ASCII plain text into an MCU's flash - the ASCII plain text file is not written into flash memory and then executed. Certainly a microprocessor could read ASCII text and interpret it under program control, but the ASCII text is not itself loaded into flash and executed.
    – Nick Gammon
    Jun 21, 2023 at 6:53
  • I see, so it is the wording of "to read". You mean "to read for execution" and I understood "to read for programming the flash". As there might be more like me, would you mind to enhance the answer? -- Because it were a waste of space to store programs in ASCII coded hex, I did not think of this. Jun 21, 2023 at 7:23
  • I have attempted to explain it better.
    – Nick Gammon
    Jun 21, 2023 at 7:47
  • :-D Wow. Yes, it's cool to explain Intelhex, and a good thing in the context. -- Please don't get it wrong, my humble issue targets just the "to read" in the second sentence, and it can be clarified satisfyingly with the content of your first comment. Jun 21, 2023 at 8:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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