The short form of the answer is that it is entirely dependent on the organization and its standards and customs.
For the longer answer, start by looking at the way the word "master" is used in English and notice that it has several meanings that are only loosely related. "Master" can mean "teacher", it can mean "lord" especially when referring to the "master of an estate" or "master of slaves", or it can mean "expert" as in master of the art. Its worth noting that the division between these meanings is clearer in some other languages. In Latin, both "magister" and "dominus" are often translated into the English word "Master" but their meanings are distinct in Latin. "Magister" refers to a master of an art or an expert while "dominus" referred to someone in authority as in a "master of an estate" or "slave master". Etymologically, our word "master" derived from the Latin "magister" but went through several changes and the definition broadened substantially.
You can see all of these intermingled in martial arts, and as Dave Liepmann pointed out, often in confusing ways. Some organizations, both in and out of martial arts, have specific and detailed criteria for attaining the rank of master in their art. A master of chess has an ELO rating of at least 2200 and meets certain other criteria. A master penman has been recognized by IAMPETH as being a master of their craft. In ITF a master is someone who has been recognized as a 7th or 8th Dan and a grandmaster is someone who has been recognized as 9th Dan.
In the sense of someone being a teacher, I do not think it would ever be wrong to call your sensei/coach/instructor "master". But that can easily get confused with other meanings of the word, especially if you are in an organization that has precisely defined the term. I have never seen the term "grandmaster" used to refer to the "teacher of my teacher". Grandmaster as a term generally either refers to a precisely defined rank (ITF 9D for instance) or else to someone who outranks the masters in an organization that recognizes masters.
All of this is a long way of saying that referring to a teacher as "master" will not be wrong, but can be confusing and ambiguous. For any other meaning of the word you need to look specifically at the culture and standards of a particular organization.