Defamation (also known as calumny, vilification, libel, slander, or traducement) is the oral or written communication of a false statement about another that unjustly harms their reputation and usually constitutes a tort or crime. In several countries, including South Korea, a true statement can also be considered defamation.
Under common law, to constitute defamation, a claim must generally be false and must have been made to someone other than the person defamed.
So, to protect yourself, don't say things that could harm the ex-employer's reputation, or, if you do, be sure you can prove that what you said is objectively true or obviously a statement of personal opinion. "Joe is a a dickhead" is a statement of opinion and not defamatory. If you say "Joe is a thief", you better be able to produce the record of his conviction for larceny.
If your contract with an ex-employer with such a clause then you must abide by it. This will limit what you can say about the ex-employer as spelled out in the contract - it may be you can't say anything negative but it may also be that you can't say anything at all.
Breach of confidence
Legally enforceable obligations to maintain confidence may arise in contract and equity.
A contractual obligation of confidence can arise from express terms in a contract, but also by implication.
An equitable obligation of confidence can arise where the formalities for the formation of a contract are not present. The obligation arises where information with the necessary quality of confidence is imparted in circumstances importing an obligation of confidence. Such circumstances will exist where the information is imparted on the understanding that it is to be treated by the confidant on a limited basis, or where the confidant ought to have realised that in all the circumstances the information was to be treated in such a way. Breach of the obligation occurs where there is an unauthorised use, not only where there is unauthorised disclosure, of the information.
Depending on your role with the ex-employer, you may retain fiduciary duties that continue beyond the end of your relationship. Ex-directors certainly have such duties but sufficiently tightly placed non-director executives (C suite level) may also have these.