You mean "Who took the cookie off the counter" "Not me" kind of lying? Unless they have a brain injury the know they took the cookie and are telling you different. In that way they know they are lying. Do they really understand ...depends on the kid. 2 of mine clearly understood about it by age 3. One that didn't 'get it' until a little past 4.
The 3 yr old doesn't know right from wrong yet. There is a lot of imagination, tho. Just ask if he's telling you a story or is this what really happened. The 6 yr old may be telling the truth. I told mine that lying would get worse punishment. Tell me the truth and we'll talk about it.