For any give stock, in TWS (and on any other broker) there is a reported options historical volatility and an options implied volatility. I know the historical volatility is the annualized standard deviation of the stock. But how is the implied volatility determined?

I am aware that the implied volatility is the volatility the market expects in the future. But how far in the future? i.e is it the implied volatility using options that will expire in one year? Is it the implied volatility using options of expiry of one month? Is it determined using at the money or in the money options?

I don't need to know the mathematical model used (if it's based on black scholes or not), I basically just would like to know some general information about how the stock's IV is determined. i.e What options with what strike prices and expiry dates are used to determine the IV.

Basically I would like to know the following... After I know there are cheap options based on low implied volatility percentile, how should I proceed to buy the option? Since there are many options with different IVs, which option should I buy? The one with the closest IV compared to the one of the stock? Or what?

Thanks in advance.