Words that sound alike but have different meanings and spellings, such as “to” and “two,” are called homophones. The two words share a pronunciation but differ in what they mean, and in this example they also differ in spelling.
The prefix homo- means “same,” while phone comes from Greek for “sound.” Homophones can have different spellings, as with “pair” and “pear,” or the three-way set “to,” “too,” and “two.” They can also be spelled identically, as with “rose” meaning a flower and “rose” meaning got up; context then reveals the intended meaning.
A useful related term is heterograph. It describes homophones that are spelled differently, such as “right” and “write.” Homophones are often confused in writing because pronunciation alone cannot distinguish them. Grammar and context supply the missing information: “I went to the store” uses the preposition, while “two apples” uses the number. Homophones also vary by accent, so pairs that sound identical in one variety of English may be distinct in another.