How each format compresses
JPG uses lossy compression. It studies the image, then throws away detail it expects you will not notice. The file gets much smaller, but the discarded detail never comes back. Every time you open and save a JPG, it compresses again and the image degrades a little more.
PNG uses lossless compression. It stores every pixel exactly and packs the data more tightly. Nothing is thrown away, so the file stays identical through any number of edits and saves. The tradeoff is size: the same photo is usually much larger as a PNG than as a JPG.
Transparency and sharp edges
PNG supports an alpha channel, so parts of an image can be fully or partly transparent. Logos, icons, stickers, and cutout product shots need that. JPG has no transparency at all; every pixel is opaque, and a transparent area saved as JPG turns into a solid background color.
PNG is also kinder to hard edges. Text, screenshots, and line art stay crisp because compression does not blur boundaries. JPG works best on photographs and smooth gradients, where its compression hides inside soft color changes. Push a JPG too far and you start to see blocks and halos.
Which format you should use
Default to JPG for photographs, scans, and any image that has to stay small. Default to PNG when transparency matters, when the image contains text or sharp lines, or when you plan to edit and re-save it several times. Most web images only need one of those two.
If you picked the wrong one, conversion takes a second. Turning a JPG into a PNG gives you a PNG container but cannot restore detail the JPG already lost, and turning a PNG photo into a JPG saves space but removes transparency. Both conversions run in the browser with no install.