Advance of d4 in the Ruy Lopez I was White in this position, and Black had just played f6.

[FEN "r1bqkb1r/ppppn1pp/2n2p2/1B2p3/4P3/5N2/PPPP1PPP/RNBQ1RK1 w kq - 0 1"]


I played c3 to prepare a push of d4 and strike the center.

When analyzing this position later, the engine suggested that 5. d4 Nxd4 6. Nxd4 exd4 7. Qxd4 was superior (+1.7) than my 5. c3 (+0).

I don't really understand what White advantage has in this line. In general, I don't really know when I should exchange the d4 pawn in the Ruy Lopez and what benefit I get from such exchanges of central pawns. Can anyone help me understand?
First, I agree that f6 is both weakening and a waste of time.

The real crux of the matter is that in most double-king pawn openings, white tries to play d4 and after the trade e5xd4, he tries to outpost a N on d5, which exerts great pressure on black. If black can play d5, and I do not agree that he has the initiative there after the better d3, he does get easy equality with plenty of space.

In both this opening, and in most Sicilians, you should be on the lookout for when black can play d5. If he gets it in, then he usually has gained equality, so you want to think prophylactically, and play moves that inhibit d5.

Your plan of trying to put two pawns in the center is admirable, but if it were possible, it would be excellent, however, it is just not possible there.