The rule is short enough to remember: photographs go as JPEG, everything else goes as PNG. Almost every oversized-attachment problem is a screenshot saved as PNG when it should have been a JPEG, or a photograph saved as PNG when it should have been anything else.
Why the rule works
JPEG throws away detail your eye does not miss, which works beautifully on the gradual variation of a photograph and badly on the hard edges of text. PNG keeps every pixel exactly, which is right for a screenshot of an interface and enormously wasteful for a beach.
- Photograph, no text: JPEG, and the file will be roughly a tenth the size.
- Screenshot, diagram, logo, anything with text: PNG, and the edges stay crisp.
- Needs a transparent background: PNG, always. JPEG cannot do transparency at all.
- Going on a website you control: WebP, which beats both.
The one trap
Converting a PNG with a transparent background to JPEG fills the transparency with something — usually black, sometimes white, and you rarely get to choose. If your logo comes back on a black rectangle, this is what happened.
Worth knowing
Converting a JPEG to PNG does not restore the detail JPEG discarded. It just stores the discarded version losslessly, in a bigger file.