The shape of the URL
data: + a media type + , + the data, with ;base64 before the comma when the data is base64. The media type may carry a charset, as in data:text/plain;charset=utf-8,…. Everything after the first comma is the data, which is why a comma inside an SVG has to be percent-encoded and why a missing comma is the failure this page names first.
A fragment after the body is not part of the data: ...#icon addresses an element inside an SVG document, and browsers treat everything from # as belonging to the page. That is one of the two characters that must always be escaped in a hand-written URI, the other being the percent sign itself.
Base64, and the third it costs
Base64 maps three bytes onto four characters from a 64 character alphabet. The result is 4/3 of the input, plus padding, plus the media type, which on a small icon is most of the URL. It carries any bytes, including binary, and it survives being copied through almost anything, which is why it is the default here and the only option for images and fonts.
The cost is not only size. A base64 image has to be decoded before it can be painted, and it cannot be cached separately from the document that carries it. For a 1 KB icon in a stylesheet that is invisible; for a 200 KB hero photograph it delays the first paint of the whole page.
Percent-encoding, and why an SVG likes it
A URL may carry letters, digits and a set of punctuation unescaped, so an SVG full of element names loses very little. Only <, >, #, %, the quote and the space become %XX, and after comments and indentation are removed the URI is often shorter than the source file. The catch is that it only works for text: percent-decoding produces bytes, and any byte that is not valid UTF-8 in the original does not come back.
Both encodings have to be quoted correctly where they are used. In CSS, url() accepts an unquoted URI with no spaces, parentheses or quotes; in HTML, an attribute needs its own quotes not to collide with the ones inside the data. The snippets on this page escape the double quote, which is the character that breaks an HTML attribute first.
When a real file wins
An asset used once, small, and needed before the stylesheet is parsed: a URI is a win, because the request it removes is a round trip that would otherwise happen. An asset used on every page, or large enough that the base64 overhead passes a few kilobytes: a file with a long cache header is better, because the browser downloads it once and reuses it across pages, which an inline URI cannot do.
The rule of thumb most performance guides settle on is a threshold around 2 KB of encoded output. Beyond it, the extra parse and the lost cache entry cost more than the request saved, and a page made of twenty inlined fonts is slower than the same page with ten real files.
What a data URI must not carry
Not a script, and not a page. Browsers refuse data: for top level navigation, most refuse it as a script source, and a strict content policy has to name data: explicitly in img-src or font-src before an inline asset loads at all. This page's own policy allows data: for images and fonts only, which is the shape a policy should take if it needs them.
For user-supplied content, a data URI is still user-supplied content: a decoded SVG can contain a script, and an <img> will not run it but an <object> or an inline SVG can. Decode a stranger's URI here to inspect it, and do not put it back into a page unexamined.
When the question is the encoding alone, Pikkola Base64 keeps the bytes and drops the media type. When the markup inside the URI needs drawing first, Pikkola SVG Studio writes it.