The five characters that matter
HTML gives a few characters special jobs, so they have to be written as entities when you mean them as plain text:
&starts every entity, so a bare&can be read as the start of one. It becomes&.<starts a tag. It becomes<.>ends a tag. It becomes>."ends an attribute value written in double quotes. It becomes".'ends an attribute value written in single quotes. It becomes'.
Strictly, text content needs only & and < escaped, and an attribute in double quotes needs only & and ". Escaping all five everywhere is simple and always safe.
Named, decimal and hex entities
é, é and é are three ways to write the same character, é. A named entity is easy to read, but only some characters have a name: HTML 4 defines 252, and HTML 5 adds a few thousand more. A numeric entity works for every Unicode character, in decimal after &# or in hex after &#x.
This tool writes ' for the apostrophe instead of '. HTML 4 does not define ', so numbers are the version that works everywhere.
Do you need to escape non-ASCII characters?
Usually not. If a page is saved as UTF-8 and declares it, with <meta charset="utf-8"> or a matching Content-Type header, é, 你 and emoji can be written directly. Escape non-ASCII characters only when the text has to travel through something that cannot carry UTF-8, such as a very old system or an ASCII-only file.
Entities are still useful for characters that are invisible or easy to confuse. is a space that does not break a line, and ­ marks a place where a long word may be hyphenated. Writing them as entities makes them visible in your source.
Escaping is not the same as sanitizing
Writing <script> as <script> makes a browser show the text instead of running it, which is exactly right for text that goes in the body of a page. But the correct escaping depends on where text lands: the HTML body, an attribute, JavaScript, a URL and CSS each need their own method. Use your template engine's automatic escaping, and treat a converter like this one as a way to look at and fix individual strings.