flashman
← All guides

Fit a QR payload at error correction M

Fit a payload into a QR symbol at error correction M: the encoder picks a mode, spaces count, and version 40 is the last size this generator will draw.

2026-10-21 · 7 min read

  • qr
  • encoding
  • tooling

The QR page encodes the text box to a PNG data URL. The options are fixed: error correction M, margin 1, and width 320. There is no selector for a smaller symbol or a higher correction level. A box that trims to nothing clears the image. Every other character is payload, including spaces and newlines.

The library chooses numeric, alphanumeric, or byte mode from the characters. That choice, together with level M, sets the longest string version 40 can hold.

Match the mode to the characters

Digits use numeric mode. A string of 4000 zeros still encodes, so a long numeric id is not the first thing that will fail. Uppercase letters and spaces use alphanumeric mode. 3391 A's encode at version 40. The next A throws The amount of data is too big to be stored in a QR Code.

Lowercase letters and characters such as { use byte mode. 2331 a's fit. The next a throws the same sentence. é is two UTF-8 bytes, so 1165 of them fit and 1166 do not. A URL such as https://flashman.dev uses byte mode because of the lowercase letters and the punctuation, and that short URL is version 2.

  • Count the final string, not the draft without spaces.
  • Expect lowercase to cap near 2331 characters.
  • Expect an uppercase-only code to cap at 3391.
  • Treat the thrown sentence as a size error.

Keep spaces if the scanner must see them

hi and the same letters with two spaces on each side produce different data URLs. The page does not trim a box that contains other characters. A newline stays in the payload. If the scanned value is a coupon or a one-time code, those extra characters will fail an equality check later.

Clear the sample before you paste. The empty state is the only input that skips the encoder. A box of only spaces trims to nothing, so the image stays blank. A space beside a letter is encoded.

Save the PNG you can regenerate

The image starts with data:image/png;base64, and the download name is flashman-qr.png. Margin 1 is the quiet zone. Width 320 is the bitmap size, not the version. Version grows as the text grows, up to version 40, which is 177 modules on a side before the quiet zone.

If the text is one character over the limit, shorten it or move the long part to a URL the symbol can hold. This page cannot switch to error correction L to buy more capacity, and it cannot switch to H to buy more damage resistance.

Check the text, then the symbol

Paste the exact payload, wait for the image, and scan it back to the same characters. Diff the scanned text against the box when a wrapper added a space or a newline. For a data URL you copied by hand, the Base64 page can decode the PNG bytes only after you remove the data:image/png;base64, prefix, and those bytes are not UTF-8 text.

Use the QR tool for the symbol, the URL tool when the payload is an address, the Base64 tool for the data URL prefix, and diff for the scanned text against the source. Store the source string next to the PNG so the next edit can be measured before it is printed.

Try these tools