The common law has an ancient principle that affords a privilege to individuals excusing them from giving evidence that is self-incriminating. In Environment Protection Authority v Caltex Refining Co Pty Ltd  HCA 74; (1993) 178 CLR 477. Mason CJ and Toohey J note, at :
Historically, the privilege developed to protect individual human persons from being compelled to testify, on pain of excommunication or physical punishment, to their own guilt.
and that one basis of the privilege was:
the common law’s reaction against the use of the ex officio oath by ecclesiastical courts and the Court of Star Chamber and against the unjust methods of interrogating accused persons, culminating in 1645 in a declaration that the use of the oath was unlawful…
In NSW (and around Australia under the various uniform Evidence Acts), the requirements to benefit from a privilege has been set out in statute. Section 128 of the Evidence Act 1995 (NSW) provides that a person seeking to avail themselves of the privilege must first:
- Object to giving evidence;
- On the ground that the evidence may tend to prove that the witness has either committed an offence or is liable to civil penalty.
The court must satisfy itself that there are reasonable grounds for the objection.
If evidence is given without objection it is not possible to later apply for the privilege.
If the court requires you to give evidence in the interests of justice it must give you a certificate of immunity which prevents the evidence given under objection being used against the witness.
Naturally, as if often the case with statute, there are other complexities and you should obtain legal advice regarding you own situation.