An SVG optimizer can return a file that is smaller and still broken. The most common sign is the text NaN inside a path element, in place of a coordinate. SVG Optimize is a free browser tool for people who need a smaller SVG without uploading the file. This page explains what NaN in an SVG means, how to check a file for it, and why a preview can look correct while the downloaded file does not.
What NaN in a path actually means
A path is a list of drawing commands followed by numbers. Each command says what to draw, and the numbers give the coordinates. Producing the file requires a long chain of number handling: parse the values, convert relative distances into absolute ones, round them, and print them again. NaN is what the optimizer writes when one of those steps produces a value that is not a number at all. The string NaN is shorter than almost any real coordinate, which is why a broken file can still report a smaller size.
The browser cannot draw a path that contains this token. Depending on where it appears, the result is a missing subpath, a shape with the wrong outline, or an empty image. Nothing in the file announces the failure: there is no error message and the markup is otherwise well-formed, so the file opens without complaint in an editor.
The arc command with joined flags
When this problem was traced through an older optimizer build, the trigger turned out to be a syntax detail in arc commands, not the artwork. An arc command, written A for absolute or a for relative, takes seven numbers: two radii, a rotation, two flags, and a destination point. The two flags are single digits, and SVG allows them to be written without a separating space.
Both lines below describe the same arc. The first packs the flags into one token; the second separates them.
<path d="M2 2A1 1 0 01 0 2z"/> <!-- flags written as 01 -->
<path d="M2 2A1 1 0 0 1 0 2z"/> <!-- flags written as 0 1 -->In the tested build, the first form produced a1 1 0 1 0 0 NaN — a coordinate replaced by NaN. The second form produced correct output. Two further findings are worth knowing. The bug did not reproduce when the output of that build was fed back into it, because the optimizer writes flags with a space on the way out. And it depended on the input only: the same file could fail in one optimizer version and succeed in another, because the parsing and number formatting code differs between versions.
| Input form | Result in the tested build | What to conclude |
|---|---|---|
A1 1 0 01 0 2 (flags joined) | Coordinate replaced by NaN | Check any file that uses this form. |
A1 1 0 0 1 0 2 (flags separated) | Correct output | The form is safe in the version tested; still verify the drawing. |
| Any file, another optimizer version | Not determined | Version matters, so test with the tool you actually use. |
Source: the arc command is defined in the W3C SVG path specification, which states that the flags are single digits and that a comma or whitespace separator is optional before them.
Why the preview does not catch it
A preview can be produced from the original markup rather than from the optimized output. When that happens, the image on screen is a faithful rendering of your source file, displayed next to a size comparison that refers to the new bytes. The two halves of the interface describe different files, and the difference is invisible until the download is opened in a browser.
Even a preview built from the real output can miss the damage at the wrong scale. Icons are usually shown large in a tool and small on the page. A missing subpath inside a letter or a gap in a fine outline is easy to overlook at icon size and obvious when the same file is placed in a navigation bar at 400 percent zoom. Check the result at the size it will actually be used, and check it against the original side by side.
How to check a file for NaN
The check is a text search, because the defect is a literal string in the markup. On macOS or Linux, this prints the count of occurrences per file:
grep -c NaN icon.svg
# 0 on a clean file; anything above 0 means a broken pathTo check a whole folder before publishing, use grep -rc NaN assets/. On Windows PowerShell, the equivalent is (Select-String -Path .\*.svg -Pattern NaN).Count. Without a terminal, open the file in a text editor and search for NaN; a single match is enough to reject the file.
A text search catches this defect but not every possible defect. A coordinate can be rounded into a slightly different curve, an identifier can be removed while page CSS still refers to it, and aviewBox can be dropped while the layout expects scaling. Those need a visual comparison, which is why both steps belong in the review.
For an editable check of the markup itself, the SVG Editor opens the source and the drawing together, so a removed attribute or a rewritten path can be read rather than guessed.
A short checklist before you replace an asset
| Step | What it catches |
|---|---|
| Search the output for NaN | Coordinates the optimizer failed to compute |
| Compare drawing with source at final display size | Changed curves, missing subpaths, lost detail |
| Confirm viewBox and dimensions survived | Broken scaling in responsive layouts |
| Check ids your CSS or scripts reference | Highlight, masking and animation that silently stops |
| Keep the original until the replacement is verified | Lost source if the result turns out unusable |
None of these steps takes long for a single icon, and together they cost less than discovering a broken logo on a production page. The size number is evidence about bytes, not about correctness.
What to do with a file that comes back broken
Keep the original and record the optimizer version and the settings you used. Try the same file with a different version or with the pass that rewrites paths turned off, since that is the pass most likely to be responsible. If the file came from an icon library, check whether a newer release of the library has been re-exported, because upstream fixes sometimes remove the syntax that triggers the problem.
In SVG Optimize, Convert path data is one of the switches in the panel. Turning it off leaves the path commands as they were written and gives up most of the size reduction on path-heavy artwork, so it is a fallback rather than a default. For a batch, use SVG Compressor and check every result before downloading, because files in the same folder can behave differently. Single files can be reviewed on SVG Optimize.
Frequently asked questions
Why does the optimized SVG show NaN in the path data?
A NaN in a path is a number the optimizer failed to compute. It is not a valid coordinate, so the browser stops drawing that subpath. It usually comes from an optimizer bug rather than from your file, and in a tested build it appeared when an arc command was written with its two flags joined together, such as 01 instead of 0 1.
How can I check whether my optimized SVG is broken?
Search the file for the text NaN. In a terminal, grep -c NaN file.svg returns the number of occurrences, and anything above zero is a defect. If you have no terminal, open the file in a text editor and search for NaN. Also render the file in a browser at the size you use on the page, because a path containing NaN can leave a blank area that a small preview hides.
Does a smaller file size mean the SVG is still correct?
No. A broken file can be smaller than the original because the coordinates were replaced by short text. Compare the drawing, not only the byte count: open the result next to the source at the same display size, and check small details such as narrow strokes, counters inside letters, and curves on the outside edges.
Should I keep the original SVG before optimizing?
Yes. Keep an untouched copy of every file you process. If the optimizer produces a broken result, the original is the only reliable way to recover, and it also lets you compare versions and report the problem accurately. A version control system or a separate folder both work.
Which SVG export style is most likely to trigger this?
Files whose paths contain arc commands with the two flag values packed into a single token, for example A1.73 1.73 0 010 17.655 instead of A1.73 1.73 0 0 1 0 17.655. Both forms are valid SVG. Editors and icon libraries that minify output aggressively produce the packed form, so checking the result matters most for those files.