The optimum altitude depends on your aircraft, the engines and the weather. But most important is to decide what you are trying to achieve. If you would like to optimize your fuel consumption per distance travelled, the altitude you will fly at will be higher than if you try to optimize your fuel consumption per time unit.
Fuel per distance travelled is usually better at altitude, while fuel flow per time unit is lower at lower altitudes. In other words, if you want to go far, fly high. If you want to keep flying long, fly low.
Winds play an important role as well. If you have a strong headwind high up, you might go further staying low.
There is quite some difference between reciprocating engines and jet / turbine engines here. The former perform better at lower altitudes, while the latter do just fine until much higher.