The burden of proof never “shifts”
It always remains with the prosecution or the plaintiff (P) to prove their case to the required standard; the defendant (D) never has to prove anything.
As this is a criminal trial the burden or obligation of proof of the guilt of the accused is placed squarely on the Crown. That burden rests upon the Crown in respect of every element or essential fact that makes up the offence charged. That burden never shifts to the accused. There is no obligation on the accused to prove any fact or issue that is in dispute. It is not for the accused to prove their innocence but for the Crown to prove their guilt.
NSW Criminal Trial Courts Bench Book
In summary, the P asserts that the required elements of the case happened and provides evidence to prove that they did. In theory, and very occasionally in practice, the D does not have to make a case at all because they don’t have to prove anything - that’s what a motion to dismiss is for. However, the normal course is for the D to provide evidence that one or more of the elements didn't happen.
The decision by the trier of fact is a wholistic one - has the P proved their case to the required standard. This is not a game of tennis, where the parties take turns meeting their burden, so, in that sense there is never a “shift”; at least, not one that happens in a courtroom.
Historically, to be criminally liable a person had to possess mens rea (a guilty mind). That doesn’t necessarily mean that they had to know what they were doing was illegal, because ignorance of the law is not an excuse, but that their actus rea (what they actually did) was done intentionally. That is, you don’t have to know that killing someone is illegal but if you deliberately, without lawful excuse, end another person’s life, you’re guilty of murder. Where men’s rea is a criteria, P has to prove that D had the requisite state of mind.
Strict liability crimes are proven if P shows that D dis whatever it is that is prescribed. There is no reverse onus here, P still has to prove D did ‘it’ to the required standard.
Similarly, where the elements are recklessness or negligence, P has to prove that D didn’t do whatever it is that would have met that standard. Indeed, there have been successful appeals where, when negligence was the standard, P didn’t demonstrate that there was something D could have done.
Parliament can reverse the evidential or legal onus by statute
It is possible that there are circumstances where D is not liable even though P has made out all the elements (or they have been agreed).
The classic is, of course, self-defence as a defence to many violent criminal charges, but there are others. For example, necessity is a common law defence to most crimes, truth is a defence to defamation, or a statute may provide that such-and-such is an offence without "reasonable excuse” or that there is a rebuttable assumption.
In general, these place an evidential burden on D.
evidential burden, in relation to a matter, means the burden of adducing or pointing to evidence that suggests a reasonable possibility that the matter exists or does not exist.
s13.3 Commonwealth Criminal Code
If D wishes to claim an affirmative defence, and the evidence that P advanced in their case does not raise “reasonable possibility” for it, a burden is placed on D to provide that evidence. However, the legal burden for proving that D does not have the defence remains with P.
So, for example, if D wants to rely on a necessity defence, P is unlikely to provide evidence that what D said was necessary (at least, not on purpose). Therefore, for the defence to be made out, D has to provide evidence “that suggests a reasonable possibility” that their actions were necessary in the circumstances. However, the legal burden to prove their case remains with P. That is, P will need to provide sufficient evidence to overcome D’s “reasonable possibility” to the required standard.
Occasionally, a statute will move the legal burden to D.
A burden of proof that a law imposes on the defendant is a legal burden if and only if the law expressly:
(a) specifies that the burden of proof in relation to the matter in question is a legal burden; or
(b) requires the defendant to prove the matter; or
(c) creates a presumption that the matter exists unless the contrary is proved.
s13.4 Commonwealth Criminal Code
The standard that D has to meet is always the balance of probabilities, never beyond reasonable doubt. See s13.5 Commonwealth Criminal Code and:
In the type of case now before you, however, there is an exception to the general propositions of law which I have just put, namely — that the Crown must prove its case, and prove it beyond reasonable doubt. The law makes provision in respect of one matter which arises for your decision in this trial, in which the accused must prove their case. I will explain shortly what that matter is.
Now however, I wish to emphasise that the law is that where the proof of any matter is on an accused person, that is to say, by way of exception to the general rule which I have explained, then the accused is not required to prove that matter beyond reasonable doubt — the standard of proof imposed upon the Crown.
The accused needs only to establish what the accused relies upon, in this regard, to a lower standard of proof than beyond reasonable doubt. The accused is required to prove the accused’s case, in this regard, only on the balance of probabilities. That is to say the accused needs only to show that it is more likely than not that what the accused asserts is so.
NSW Criminal Trial Courts Bench Book
Now, the transfer of either the evidential or legal burden is colloquially referred to as “shifting the burden” but never by a judge and never in a courtroom.
The law is essentially the same in the UK.
s136 creates a rebuttable assumption that D contravened the act and puts an evidential burden on them to provide another explanation for the contravention. Notably, this is only the case for civil contraventions as crimson contraventions are explicitly carved out of s136.