There are 3 numbered mainline Kingdom Hearts games: Kingdom Hearts, Kingdom Hearts II, and Kingdom Hearts III.
The numbering refers to the central console entries in the series, rather than every game released under the Kingdom Hearts name. Kingdom Hearts began the story in 2002, Kingdom Hearts II continued it in 2005, and Kingdom Hearts III concluded the Dark Seeker Saga in 2019.
The series has many other important games, including Chain of Memories, Birth by Sleep, 358/2 Days, Dream Drop Distance, and Melody of Memory. These titles expand the story and are often essential for understanding the plot, but they are generally treated as side entries or intermediate chapters rather than numbered mainline games.
A common mix-up is counting Kingdom Hearts II as the third game released, because Chain of Memories came between the first two numbered titles. Release order and numbered-mainline order are different: Kingdom Hearts II is the second numbered mainline game, while Kingdom Hearts III is the third.