When to encode HTML
To show a code sample on a web page, to put a user's text into a template without it being read as markup, or to paste content into an email or a CMS field that interprets HTML. Decoding helps when an export or an API hands you text full of " and é.
What is encoded
The characters that change the meaning of HTML (<, >, &, " and ') are always encoded; you can also encode every non-ASCII character as a numeric entity for systems that mangle accents. The decoder understands all named entities ( , ©, é) and numeric ones, decimal or hexadecimal. Encoding is one layer of XSS protection, not a substitute for your framework's escaping.