A stack is like a pile. 
A stack is like a pile of things. 
A stack is a way to organize data. It works like a pile of plates. 
There are two main steps in a stack. The first is called push. This means you add a new item to the top. The second is called pop. This means you take the top item off. Because of this, the last item you add is the first one you take away. Scientists call this LIFO. LIFO stands for last in, first out.
You can also use a step called peek. This lets you look at the top item. It does not move the item or change the stack.
Sometimes, a stack can have problems. If the stack is full, it is called a stack overflow. This happens when you try to push an item but there is no room. If the stack is empty, it is called an underflow. This happens if you try to pop an item when nothing is there. 
A stack is a special way to organize information in a computer. It is called an abstract data type. This means it describes how data behaves rather than how it is built. You can imagine a stack of plates in a cafeteria. 
There are two main ways to change a stack. The first way is called a push. A push adds a new item to the top of the collection. The second way is called a pop. A pop removes the most recent item from the top. You can also use a tool called a peek. A peek lets you look at the top item without moving it. 

People have been using these ideas for a long time. In 1946, a famous scientist named Alan Turing used similar ideas. He used the words "bury" and "unbury" to talk about computer tasks. In 1945, Konrad Zuse built a machine called the Z4 that used a two-level stack. Later, in 1955, Klaus Samelson and Friedrich L. Bauer proposed a stack idea. They called it an "operational cellar." They even filed a patent for it in 1957.
Computer scientists build stacks in different ways. One way is using an array, which is a list of items in a row. Another way is using a linked list. A linked list uses pointers to connect one item to the next. 
Stacks are helpful because they follow very strict rules. They have a fixed bottom and a moving top. A stack pointer is a tool that keeps track of where the top is. This is very important for computer hardware. Some machines, like the PDP-11, use special modes to handle stacks. Even small tools like programmable calculators use these concepts to work. 
In computer science, a stack is an abstract data type used to organize collections of elements. An abstract data type defines how data behaves rather than how it is physically stored in memory. A stack is a sequential collection with one end that is fixed, called the bottom. The other end is the top, which is the only position where data can be added or removed. This structure follows a specific order known as LIFO, or Last In, First Out. This means the most recent item added to the stack is always the first one to be removed.
To understand how a stack works, we can look at its primary operations. The first essential operation is called a push. A push adds a new element to the very top of the collection. The second essential operation is called a pop. A pop removes the most recently added element from the top. There is also a non-essential operation called a peek, or top of stack. A peek allows a user to observe the value of the top element without modifying the stack. 
Stacks can encounter specific error states based on their capacity. If a stack has a bounded capacity, it can only hold a certain number of items. When the stack is full and cannot accept more elements, it enters a state called stack overflow. Conversely, if a user attempts to perform a pop or a peek operation on an empty stack, it results in a stack underflow. These conditions are critical for programmers to manage to prevent system errors. 
History shows that the concept of the stack has evolved since the mid-1940s. In 1946, Alan Turing used the terms "bury" and "unbury" to describe calling and returning from subroutines. By 1945, Konrad Zuse had already implemented subroutines and a two-level stack in his Z4 machine. In 1955, Klaus Samelson and Friedrich L. Bauer proposed an "operational cellar" concept. They filed a patent for this idea in 1957. Later, in March 1988, Bauer received the IEEE Computer Pioneer Award for his work on the stack principle.
Computer scientists implement stacks using different underlying structures. One common method is using an array. In an array-based stack, the program tracks the size using a variable called "top." This variable points to the index where the next element will be inserted. Another method is using a singly linked list. In this implementation, the stack is a pointer to the head of the list. A linked-list stack can grow as long as there is available memory, making overflow unlikely.
Many modern programming languages utilize stack operations within their standard libraries. Languages such as Perl, LISP, JavaScript, and Python include push and pop functions for their list types. Some families of languages, like Forth, are designed entirely around stacks that programmers manipulate directly. In the C++ Standard Library, certain container types provide LIFO semantics. Even specialized hardware, like the PDP-11 or Motorola 68000 series, includes addressing modes specifically designed for stack manipulation.
At the hardware level, stacks are vital for managing computer memory and architecture. A stack is typically an area of memory with a fixed origin and a variable size. A specialized tool called a stack pointer keeps track of the most recent location. When a push occurs, the stack pointer is adjusted to accommodate the new data. When a pop occurs, the data is read and the pointer moves back. This mechanism allows processors to efficiently allocate and access memory during complex tasks. 
🖼️ Images & Media (9)
More to explore
✨ What else?
Related topics you might enjoy
🔬 Go deeper
More advanced topics to explore
🪜 Step back
Simpler topics to build understanding
What is Nepedia?
A free, ad-free encyclopedia for children. Every article is written at five reading levels, so the same page works for a five-year-old and a fifteen-year-old — use the level switcher above to see this one change. No account needed to read.