You use if to introduce a conditional clause in which you mention a possible situation.
If you get tired, have a rest.
If the machine stops working, call this number.
You can use if to mention a situation that might exist in the future. In the conditional clause, you use the present simple form. Don't use a future form.
If all goes well, we will arrive by lunchtime.
If you make a mistake, you will have to start again.
You sometimes use if in a conditional clause to suggest that someone does something. You usually use the present simple in the conditional clause.
If you turn to page 15, you will see a list of questions.
You can use if to mention a situation that sometimes existed in the past. You usually use the past simple in the conditional clause.
They ate outside if it was sunny.
If we had enough money, we used to go to the cinema.
You can also use if to mention something that might have happened in the past, but did not in fact happen. In the conditional clause, you use the past perfect. Don't use the past simple.
If he had known the truth, he would have run away.
If they had not met, this book would never have been written.
You also use if in conditional clauses to mention situations that do not exist, or events that are unlikely to happen. In the conditional clause, you use the past simple. Don't use a present tense.
They would find it difficult to get a job if they left the farm.
If she wanted to, she could be a dancer.
In formal writing, when the subject of the conditional clause is I, he, she, it, there, or a singular noun, you use were in the clause instead of ‘was’.
If a problem were to arise, she would be able to resolve it.
Employees would be more productive if better resources were provided.
In conversation or informal writing people usually use was (except in the expression If I were you).
If I was a painter, I'd paint this garden.
We would prefer it if the test was a bit easier.
Sometimes was is used in formal writing too, but this is considered incorrect by many people.
in reported questions
If is also used in reported questions.
I asked her if I could help her.
I wonder if you understand what I mean.