The difference between "madness" and "sanity" is a jagged, blurred line. It is all related to perception, and while a majority may agree on what is sane or not, they not be thinking or perceiving on the same level as another group or person. Under extreme physical or mental stress, doors can be opened to new planes of thinking. The narrator in "The Yellow Wallpaper" by Charlotte Perkins Gilman would be considered by most to be mad.
The narrator in "The Yellow Wallpaper" had questionable sanity by the end of the book. However this was due to the fact that she wasn't allowed to express herself the way she wanted to. Her pride and individuality were taken from her. Aside from not being allowed to write, it seemed that she was kept from doing any kind of work. This includes household chores or even caring for her own son. Essentially, her will to live was taken as she felt she had no purpose. This drained her so-called "sanity" to this domestication she was forced to endure.
She not only lost her purpose in life, she apparently lost her womanhood. With the domestication of women happening, she wasn't even allowed to work and be a strong woman. She clearly felt as though there was nothing to do when she said, "So I take phosphates or phosphites-whichever it is-and tonics, and air and exercise, and journeys, and am absolutely forbidden to "work" until I am well again." The number one place where she could release her emotions and feelings was through her journal. She enjoyed reading and writing but was not allowed to do so. This drove her madder to the point that she was having hallucinogenic visions. She was in a world of her own locked up in her room and it made her see things differently.
As the narrator got worse in her insanity, she began to notice things. Many readers would see this as paranoia; however, it seems that what she saw was true. Whether her husband saw it or not, he was repressing her and it was not helping her get better.