Simply put, stream of consciousness is a style of narration that seeks to mirror the messy, random, often illogical form of human thought. Thus, stream of consciousness often defies conventional rules of grammar, and is often quite difficult to read. Some authors often associated with stream of consciousness include James Joyce, William Faulkner, and Virginia Woolf. The way in which authors use stream of consciousness is often recognizably different (Joyce's version of the technique is not the same as Woolf's, for instance), but any author's use of stream of consciousness generally aims to represent the messy (and sometimes confusing) workings of the human mind as realistically as possible.
Joyce's A Portrait of the Artist as a Young Man is one of the most famous examples of stream of consciousness narration. In this novel, Joyce's writing style mirrors the evolution and growth of his protagonist, Stephen Dedalus. As such, the beginning of the novel is written in a way that mimics a very young child's simplistic consciousness, while the latter chapters grow progressively sophisticated in order to parallel Stephen's maturation.
As an example of this technique, take a look at the first five paragraphs of the novel:
Once upon a time and a very good time it was there was a moocow coming down along the road and this moocow that was down along the road met a nicens little boy named baby tuckoo…
His father told him that story: his father looked at him through a glass: he had a hairy face.
He was baby tuckoo. The moocow came down the road where Betty Byrne lived: she sold lemon platt.
He sang that song. That was his song.
When you wet the bed, first it is warm then it gets cold. His mother put on the oilsheet. That had the queer smell.
Notice how the narration is stilted and simplistic, and also how it jumps from topic to topic with little notice or logic. While this style might flout the traditional rules of narrative, it also very skillfully mirrors the thought processes of a small child. As such, in this passage Joyce uses a stream of consciousness narrative to represent the thoughts of his young protagonist. Later on, the narrative style grows progressively more mature as Stephen himself matures.