These words are very similar to each other. Considering the structure or the surface of an object, you can use eather hart or fest.
example: Das Holz ist hart. = Das Holz ist fest.
Sometimes, it's a matter of feeling which one sounds better. Native speakers won't blame you for choosing the ,,wrong" word in a special context.
However, ,,fest" can also be used as a synonym for ,,stark" (strong):
- jemand glaubt fest an etwas. (somebody strongly believes in sth.)
- jemand hat einen festen Willen
- jemand leistet festen Widerstand
,,hart" can be used as a synonym for ,,schwierig" (tough):
- harte Zeiten
- eine harte Aufgabe
etc.
I hope that helped a bit!