How did Newton and Leibniz actually do calculus? How did Leibniz know to write derivatives as $$\frac{dy}{dx}$$ so that everything would work out? For example, the chain rule: $$\frac{dy}{dz}=\frac{dy}{dx}\frac{dx}{dz}$$ Integration by Parts: $$xy=\int d(xy)=\int x\,dy+y\,dx \implies \int x\,dy =xy-\int y\,dx$$ Separable differential equations: $$\frac{dy}{dx}=\frac{x}{y}\implies y\,dy=x\,dx\implies y^2-x^2=C$$ Even basic derivatives such as $$\frac{dx}{dx}=1$$ It seems like they cancel!
Everyone I ask always says either 1) it is essentially a lucky accident, 2) presents a "counterexample" that I usually don't think is valid, or 3) says that it can be made rigorous but that's very tedious to do... but clearly Leibniz was not in any of the three situations proposed. He must have had some reason for knowing why his notation worked so well - after all, he invented it.
As for Newton, did he know the same things as Leibniz? How come he wasn't able to come up with an equally useful notation - did he perhaps think about calculus differently?
 A: Leibniz regarded $dx$ and $dy$ respectively as infinitely small increments of $x$ and $y$, so that $dy/dx$ is the ratio of the infinitely small change in $y$ corresponding to the infinitely small change $dx$ in $x$.  Thus when $dy$ is $7$ times as big as $dx$ at a particular, point, then at that point $y$ is changing $7$ times as fast as $x$.
Leibniz regarded $\displaystyle\int_a^b f(x)\,dx$ as a sum of infinitely many infinitely small numbers $f(x)\,dx$.  Think of $dx$ as the length of an infinitely short interval on the $x$ axis, so $f(x)\,dx$ is the infinitely small area under the curve over that interval.
I answered a related question here.
Introductory calculus courses that conceal these matters are grossly dishonest.
A: The received wisdom that the success of Leibniz's framework was a "lucky accident" is in error.  Leibniz realized, and explicitly stated in a number of texts, that when he was working with "equality" this was a generalized relation where the right hand side and the left hand side were allowed to differ by a negligible infinitesimal term.  Therefore there was arguably no "inconsistency" in Leibniz's framework, contrary to Bishop Berkeley's claim.
This was discussed in detail in this recent article.
A: A derivative really is approximately a ratio of two extremely tiny (but not "infinitely small") numbers: $f'(x) \approx \frac{\Delta f}{\Delta x}$.  So, many arguments using "infinitesimals" actually make sense, if you just think of $df$ and $dx$ as being extremely tiny numbers and use $\approx$ instead of $=$, and hope (plausibly) that "in the limit" you will get true equations.
A: Obviously, they initially had different notations. Then, Leibniz realized later that the notation that is still being used today is more correct and gives a much better intuitionistic interpretation of the chain rule, e.t.c.. Newton's idea is helpful in physics and mechanics, and he was a physicist - so that makes sense, too!
A: As Michael points out, Leibniz thought of $\frac{dy}{dx}$ as a ratio between an infinitesimal quantity $dy$ and an infinitesimal quantity $dx$, and the integral as a sum of infinitesimal quantities $f(x)dx$. 
You asked if Newton had a different perspective. Indeed, Newton never considered $\frac{dy}{dx}$ to be an actual ratio of quantities: 

Those ultimate ratios with which quantities vanish ... are not actually ratios of ultimate quantities, but limits ... which they can approach so closely that their difference is less than any given quantity... [Isaac Newton, Philosophia naturalis principia mathematica.]

However even as Newton eschewed postulating the existence of infinitely small quantities, this quote alone shows that his understanding of the derivative was indeed as "ultimate ratios with which quantities vanish". The idea of $\frac{dy}{dx}$ as a ratio is fundamental to both Newton and Leibniz's presentations of and understandings of calculus, although one viewed infinitesimals as real and the basis of calculus, whereas the other viewed them as fictional and viewed the limit as the basis of calculus. 
It should be noted that just as Newton's approach to limit may be formalized using Weierstrass's $\epsilon, \delta$ definition, Leibniz's infinitesimal method may also be formalized. One approach to introducing infinitesimals is by is using Robinson's nonstandard analysis. An introductory undergraduate textbook on Calculus from a rigorous infinitesimal perspective is available from Keisler.
The fact that $\frac{dy}{dx}$ behaves like a ratio is no accident: if you work with infinitesimals or take Leibniz's perspective this is because it is a ratio (or at least the standard part of a nonstandard ratio). If you work with limits or take Newton's perspective this is because it is a limit of ratios. Either way it is to be expected and was fundamental to the discovery of calculus. 
