to notice; to realize
This pattern expresses the act of noticing or realizing something, often something that was previously overlooked.
に気がつく (ni ki ga tsuku) means 'to notice' or 'to realize'. It is used when you become aware of something through your senses or through thought. The thing noticed is marked by に. For example, if you notice a mistake in your homework, you say 宿題の間違いに気がつきました. If you realize you forgot your keys, you say 鍵を忘れたことに気がつきました. The pattern is neutral and can be used in both speaking and writing. It is often used with past tense to describe a realization that happened at a specific moment. Note that the subject is usually the person who notices, and the particle が in 気がつく is part of the idiom, so に marks what is noticed. This is a set phrase; you cannot replace が with を.