Coronavirus disease 2019 (COVID-19) is a viral disease which is declared as a pandemic by WHO. This disease is posing a global threat, and almost every country in the world is now affected by this disease. Currently, there is no vaccine for this disease, and because of this, containing COVID-19 is not an easy task. It is noticed that elderly people got severely affected by this disease specially in Europe. In the present paper, we propose and analyze a mathematical model for COVID-19 virus transmission by dividing whole population in old and young groups. We find disease-free equilibrium and the basic reproduction number (R0). We estimate the parameter corresponding to rate of transmission and rate of detection of COVID-19 using real data from Italy and Spain by least square method. We also perform sensitivity analysis to identify the key parameters which influence the basic reproduction number and hence regulate the transmission dynamics of COVID-19. Finally, we extend our proposed model to optimal control problem to explore the best cost-effective and time-dependent control strategies that can reduce the number of infectives in a specified interval of time. © 2021 John Wiley & Sons, Ltd.