“Octopus’s Garden’ is Ringo’s song. It’s only the second song Ringo wrote, and it’s lovely. Ringo gets bored playing the drums, and at home he plays a bit of piano, but he only knows about three chords. He knows about the same on guitar. I think it’s a really great song, because on the surface, it just like a daft kids’ song, but the lyrics are great.
For me, you know, I find very deep meaning in the lyrics, which Ringo probably doesn’t see, but all the thing like ‘resting our head on the sea bed’ and ‘We’ll be warm beneath the storm’ which is really great, you know. Because it’s like this level is a storm, and if you get sort of deep in your consciousness, it’s very peaceful. So Ringo’s writing his cosmic songs without noticing.”

-George Harrison
Source: The Beatles Bible
When Ringo got fed up and walked out of the White album sessions, he took his family on a boating holiday to Sardinia, where Peter Sellers loaned him his yacht
On board the yacht, the captain told him how Octopus collect shiny stones, bottles and tin cans, and use them to decorate the front of their cave like a garden
Being under the sea sounded pretty cool to Ringo right then, who at the time wanted to be anywhere except the studio, so that gave him the seed to write the song
Originally intended for the Let It Be album, it wasn’t recorded properly until the Abbey Road sessions, where George gave Ringo a hand with the arrangement.