How does the usage of "affect" and "effect" differ in English?

“Affect” and “effect” are two English words that are often used interchangeably but have different meanings. Could you explain when and how to correctly use “affect” and “effect” in English grammar? Could you also provide some examples to illustrate the differences in their usage? Do the uses of these words change in conversation versus formal writing?