Set the number too low and you ruin the file; set it too high and it gets rejected. These are the rules that work without guesswork.
Ask the destination, not the file
The right size is not decided by the file: it is decided by where it is going. A form, a mail service or an upload platform nearly always states its limit, and usually states it before giving you the error. That number is the figure you want. It pays to check it each time rather than trust what you remember, because limits change without notice and a memorised figure ages badly.
Always leave a margin
Aim below the ceiling, not at it. There are two reasons. The first is that attaching a file to a message makes it grow: the encoding mail uses adds weight in transit, so a file that only just complies can stop complying once attached. The second is that the limit usually applies to the whole message rather than to each file, so two attachments that pass separately can bounce together.
Drop resolution before quality
When the target is tight there are two ways to get there: keep the pixel dimensions and lower the quality, or reduce the dimensions while keeping decent quality. The second nearly always looks better. A slightly smaller image still looks like an image; one of the same weight with the quality on the floor fills with blocks and halos the eye picks up at once. The same holds for video, where trimming the seconds you do not need gains more than any setting.
When the target is impossible
Some files will not fit the figure you ask for and remain useful. A hundred-page scan will not come down to a megabyte and stay legible, and neither will a long video at high resolution. When that happens there are three sensible ways out: raise the target, split the file into parts, or change tack and send a link instead of the file. Insisting on the number does not make it possible; it only returns something that does not work.