Part of the show Naked Science Question and Answer
What you Need
What to do
1- Fill the jar 1/4 full of water
2- Top the glass up with oil
3- Drop in the tablet
What may happen
You should see the tablet fizzing away making foam which floats to the surface then sinks again.
Why does it happen?
The tablet includes bicarbonate of soda which has the gas carbon-dioxide locked away in its structure, and a dehydrated acid (such as citric or tartaric acid) this does not behave as an acid until you put it in water, at which point the acid releases the carbon-dioxide which forms bubbles.
The bubbles form a foam which will float in water and also in the oil, however water and oil are immiscible - they won't mix together so the foam stays in large lava-lamp like blobs and floats to the surface, where the bubbles pop and then the remaining water sinks again rejoining the water at the bottom.
How does a Real Lava Lamp Work?
A real lava lamp works on the same principle of changing the density of something so it will float and then not. It consists of two immiscible waxes, one slightly denser than the other.
The denser one is heated up by the lamp at the bottom, which makes it expand slightly, become less dense so that it will float in the other one. So it floats to the surface - a bit like a hot air balloon.
There it cools down, and sinks again, starting the process again.