differential equations – What exactly do we mean by $frac{d^2y}{dx^2}$

My maths book says $$frac{d^2y}{dx^2}=frac{d(frac{dy}{dx})}{dx}$$
I have tried to look at this by the division rule and from what I can understand, $$frac{d(frac{dy}{dx})}{dx}=frac{(d^2ydx-d^2xdy)}{(dx)^2*dx}$$

I can’t understand how both the equations can be equivalent, I understand I’m in the wrong but where am I going wrong? I was taught $dx$ can be thought of as a very small quantity, is there any such way to look at $d^2x$

My teacher also told me that $$frac{d^2x}{dy^2}=frac{dx}{dy}*left(frac{dx}{dy}right)^2*frac{d^2y}{dx^2}$$

How can the $ d^2xspace becomespace d^2y$ an equivalent would be $f”(x)space becomingspace g”(x)$ which seems quite impossible, where am I going wrong?