Zero-based numbering is a way of
numbering in which the initial element of a
sequence
In mathematics, a sequence is an enumerated collection of objects in which repetitions are allowed and order matters. Like a set, it contains members (also called ''elements'', or ''terms''). The number of elements (possibly infinite) is cal ...
is assigned the
index
Index (: indexes or indices) may refer to:
Arts, entertainment, and media Fictional entities
* Index (''A Certain Magical Index''), a character in the light novel series ''A Certain Magical Index''
* The Index, an item on the Halo Array in the ...
0, rather than the index 1 as is typical in everyday non-mathematical or non-programming circumstances. Under zero-based numbering, the initial element is sometimes termed the ''
zeroth'' element, rather than the ''first'' element; ''zeroth'' is a
coined word for the
ordinal number
In set theory, an ordinal number, or ordinal, is a generalization of ordinal numerals (first, second, th, etc.) aimed to extend enumeration to infinite sets.
A finite set can be enumerated by successively labeling each element with the leas ...
zero. In some cases, an object or value that does not (originally) belong to a given sequence, but which could be naturally placed before its initial element, may be termed the zeroth element. There is no wide agreement regarding the correctness of using zero as an ordinal (nor regarding the use of the term ''zeroth''), as it creates ambiguity for all subsequent elements of the sequence when lacking context.
Numbering sequences starting at 0 is quite common in mathematics notation, in particular in
combinatorics
Combinatorics is an area of mathematics primarily concerned with counting, both as a means and as an end to obtaining results, and certain properties of finite structures. It is closely related to many other areas of mathematics and has many ...
, though programming languages for mathematics usually index from 1. In
computer science
Computer science is the study of computation, information, and automation. Computer science spans Theoretical computer science, theoretical disciplines (such as algorithms, theory of computation, and information theory) to Applied science, ...
,
array indices usually start at 0 in modern programming languages, so computer programmers might use ''zeroth'' in situations where others might use ''first'', and so forth. In some mathematical contexts, zero-based numbering can be used without confusion, when ordinal forms have well established meaning with an obvious candidate to come before ''first''; for instance, a ''zeroth derivative'' of a function is the function itself, obtained by
differentiating zero times. Such usage corresponds to naming an element not properly belonging to the sequence but preceding it: the zeroth derivative is not really a derivative at all. However, just as the ''first derivative'' precedes the ''second derivative'', so also does the ''zeroth derivative'' (or the original function itself) precede the ''first derivative''.
Computer programming
Origin
Martin Richards, creator of the
BCPL language (a precursor of
C), designed arrays initiating at 0 as the natural position to start accessing the array contents in the language, since the value of a
pointer ''p'' used as an address accesses the position in memory.
BCPL was first compiled for the
IBM 7094; the language introduced no
run-time indirection lookups, so the indirection optimization provided by these arrays was done at compile time.
The optimization was nevertheless important.
In 1982
Edsger W. Dijkstra
Edsger Wybe Dijkstra ( ; ; 11 May 1930 – 6 August 2002) was a Dutch computer scientist, programmer, software engineer, mathematician, and science essayist.
Born in Rotterdam in the Netherlands, Dijkstra studied mathematics and physics and the ...
in his pertinent note ''Why numbering should start at zero''
argued that arrays subscripts should start at zero as the latter being the most
natural number
In mathematics, the natural numbers are the numbers 0, 1, 2, 3, and so on, possibly excluding 0. Some start counting with 0, defining the natural numbers as the non-negative integers , while others start with 1, defining them as the positive in ...
. Discussing possible designs of array ranges by enclosing them in a chained inequality, combining sharp and standard inequalities to four possibilities, demonstrating that to his conviction zero-based arrays are best represented by non-overlapping index ranges, which start at zero, alluding to
open, half-open and closed intervals as with the real numbers. Dijkstra's criteria for preferring this convention are in detail that it represents empty sequences in a more natural way than closed "intervals" (), and that with half-open "intervals" of naturals, the length of a sub-sequence equals the upper minus the lower bound ( gives possible values for ''i'', with ''a'', ''b'', ''i'' all integers).
Usage in programming languages
This usage follows from design choices embedded in many influential
programming language
A programming language is a system of notation for writing computer programs.
Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
s, including
C,
Java
Java is one of the Greater Sunda Islands in Indonesia. It is bordered by the Indian Ocean to the south and the Java Sea (a part of Pacific Ocean) to the north. With a population of 156.9 million people (including Madura) in mid 2024, proje ...
, and
Lisp
Lisp (historically LISP, an abbreviation of "list processing") is a family of programming languages with a long history and a distinctive, fully parenthesized Polish notation#Explanation, prefix notation.
Originally specified in the late 1950s, ...
. In these three, sequence types (C arrays, Java arrays and lists, and Lisp lists and vectors) are indexed beginning with the zero subscript. Particularly in C, where arrays are closely tied to
pointer arithmetic, this makes for a simpler implementation: the subscript refers to an offset from the starting position of an array, so the first element has an offset of zero.
Referencing memory by an address and an offset is represented directly in
computer hardware
Computer hardware includes the physical parts of a computer, such as the central processing unit (CPU), random-access memory (RAM), motherboard, computer data storage, graphics card, sound card, and computer case. It includes external devices ...
on virtually all computer architectures, so this design detail in C makes compilation easier, at the cost of some human factors. In this context using "zeroth" as an ordinal is not strictly correct, but a widespread habit in this profession. Some programming languages, such as
Fortran or
COBOL
COBOL (; an acronym for "common business-oriented language") is a compiled English-like computer programming language designed for business use. It is an imperative, procedural, and, since 2002, object-oriented language. COBOL is primarily ...
, have array subscripts starting with one, because they were meant as
high-level programming language
A high-level programming language is a programming language with strong Abstraction (computer science), abstraction from the details of the computer. In contrast to low-level programming languages, it may use natural language ''elements'', be ea ...
s, and as such they had to have a correspondence to the usual
ordinal numbers
In set theory, an ordinal number, or ordinal, is a generalization of ordinal numerals (first, second, th, etc.) aimed to extend enumeration to infinite sets.
A finite set can be enumerated by successively labeling each element with the leas ...
which predate the
invention of the zero by a long time. And some programming languages, e.g.,
Ada,
ALGOL 60
ALGOL 60 (short for ''Algorithmic Language 1960'') is a member of the ALGOL family of computer programming languages. It followed on from ALGOL 58 which had introduced code blocks and the begin and end pairs for delimiting them, representing a ...
,
PL/I
PL/I (Programming Language One, pronounced and sometimes written PL/1) is a procedural, imperative computer programming language initially developed by IBM. It is designed for scientific, engineering, business and system programming. It has b ...
, allow an arbitrary lower bound for each index.
Pascal allows the range of an array to be of any ordinal type (including enumerated types) and Ada allows any discrete subtype.
APL allows setting the index origin to 0 or 1 during runtime programmatically. Some recent languages, such as
Lua and
Visual Basic Visual Basic is a name for a family of programming languages from Microsoft. It may refer to:
* Visual Basic (.NET), the current version of Visual Basic launched in 2002 which runs on .NET
* Visual Basic (classic), the original Visual Basic suppo ...
, have adopted the same convention for the same reason.
Zero is the lowest unsigned integer value, one of the most fundamental types in programming and hardware design. In computer science,
zero
0 (zero) is a number representing an empty quantity. Adding (or subtracting) 0 to any number leaves that number unchanged; in mathematical terminology, 0 is the additive identity of the integers, rational numbers, real numbers, and compl ...
is thus often used as the base case for many kinds of numerical
recursion
Recursion occurs when the definition of a concept or process depends on a simpler or previous version of itself. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in m ...
. Proofs and other sorts of mathematical reasoning in computer science often begin with zero. For these reasons, in computer science it is not unusual to number from zero rather than one.
If an array is used to represent a cycle, it is convenient to obtain the index with a
modulo function, which can result in zero.
Numerical properties
With zero-based numbering, a range can be expressed as the half-open
interval, , as opposed to the closed interval, . Empty ranges, which often occur in algorithms, are tricky to express with a closed interval without resorting to obtuse conventions like . Because of this property, zero-based indexing potentially reduces
off-by-one and
fencepost errors.
On the other hand, the repeat count is calculated in advance, making the use of counting from 0 to (inclusive) less intuitive. Some authors prefer one-based indexing, as it corresponds more closely to how entities are indexed in other contexts.
Another property of this convention is in the use of
modular arithmetic
In mathematics, modular arithmetic is a system of arithmetic operations for integers, other than the usual ones from elementary arithmetic, where numbers "wrap around" when reaching a certain value, called the modulus. The modern approach to mo ...
as implemented in modern computers. Usually, the
modulo function maps any integer modulo to one of the numbers , where . Because of this, many formulas in algorithms (such as that for calculating hash table indices) can be elegantly expressed in code using the modulo operation when array indices start at zero.
Pointer operations can also be expressed more elegantly on a zero-based index due to the underlying address/offset logic mentioned above. To illustrate, suppose is the
memory address
In computing, a memory address is a reference to a specific memory location in memory used by both software and hardware. These addresses are fixed-length sequences of digits, typically displayed and handled as unsigned integers. This numeric ...
of the first element of an array, and is the index of the desired element. To compute the address of the desired element, if the index numbers count from 1, the desired address is computed by this expression:
:
where is the size of each element. In contrast, if the index numbers count from 0, the expression becomes
:
This simpler expression is more efficient to compute at
run time.
However, a language wishing to index arrays from 1 could adopt the convention that every array address is represented by ; that is, rather than using the address of the first array element, such a language would use the address of a fictitious element located immediately before the first actual element. The indexing expression for a 1-based index would then be
:
Hence, the efficiency benefit at run time of zero-based indexing is not inherent, but is an artifact of the decision to represent an array with the address of its first element rather than the address of the fictitious zeroth element. However, the address of that fictitious element could very well be the address of some other item in memory not related to the array.
Superficially, the fictitious element doesn't scale well to multidimensional arrays. Indexing multidimensional arrays from zero makes a naive (contiguous) conversion to a linear address space (systematically varying one index after the other) look simpler than when indexing from one. For instance, when mapping the three-dimensional array to a linear array , both with elements, the index in the linear array to access a specific element with in zero-based indexing, i.e. , , , and , is calculated by
:
Organizing all arrays with 1-based indices (, , , ), and assuming an analogous arrangement of the elements, gives
:
to access the same element, which arguably looks more complicated. Of course, since and A simple and everyday-life example is
positional notation
Positional notation, also known as place-value notation, positional numeral system, or simply place value, usually denotes the extension to any radix, base of the Hindu–Arabic numeral system (or decimal, decimal system). More generally, a posit ...
, which the invention of the zero made possible. In positional notation, tens, hundreds, thousands and all other digits start with zero, only units start at one.
This situation can lead to some confusion in terminology. In a zero-based indexing scheme, the first element is "element number zero"; likewise, the twelfth element is "element number eleven". Therefore, an analogy from the ordinal numbers to the quantity of objects numbered appears; the highest index of objects will be , and it refers to the th element. For this reason, the first element is sometimes referred to as the
zeroth element, in an attempt to avoid confusion.
Science
In
mathematics
Mathematics is a field of study that discovers and organizes methods, Mathematical theory, theories and theorems that are developed and Mathematical proof, proved for the needs of empirical sciences and mathematics itself. There are many ar ...
, many sequences of numbers or of
polynomials
In mathematics, a polynomial is a mathematical expression consisting of indeterminates (also called variables) and coefficients, that involves only the operations of addition, subtraction, multiplication and exponentiation to nonnegative int ...
are indexed by nonnegative integers, for example, the
Bernoulli numbers and the
Bell numbers.
In both
mechanics
Mechanics () is the area of physics concerned with the relationships between force, matter, and motion among Physical object, physical objects. Forces applied to objects may result in Displacement (vector), displacements, which are changes of ...
and
statistics
Statistics (from German language, German: ', "description of a State (polity), state, a country") is the discipline that concerns the collection, organization, analysis, interpretation, and presentation of data. In applying statistics to a s ...
, the zeroth
moment is defined, representing total mass in the case of physical
density
Density (volumetric mass density or specific mass) is the ratio of a substance's mass to its volume. The symbol most often used for density is ''ρ'' (the lower case Greek letter rho), although the Latin letter ''D'' (or ''d'') can also be u ...
, or total probability, i.e. one, for a
probability distribution
In probability theory and statistics, a probability distribution is a Function (mathematics), function that gives the probabilities of occurrence of possible events for an Experiment (probability theory), experiment. It is a mathematical descri ...
.
The ''
zeroth law of thermodynamics
The zeroth law of thermodynamics is one of the four principal laws of thermodynamics. It provides an independent definition of temperature without reference to entropy, which is defined in the second law. The law was established by Ralph H. Fowl ...
'' was formulated after the first, second, and third laws, but considered more fundamental, thus its name.
In biology, an organism is said to have zero-order intentionality if it shows "no intention of anything at all". This would include a situation where the organism's genetically predetermined phenotype results in a fitness benefit to itself, because it did not "intend" to express its genes.
In the similar sense, a computer may be considered from this perspective a zero-order intentional entity, as it does not "intend" to express the code of the programs it runs.
In biological or medical experiments, the first day of an experiment is often numbered as day 0.
Patient zero (or
index case
The index case or patient zero is the first documented patient in a disease epidemic within a population, or the first documented patient included in an epidemiological study.
It can also refer to the first case of a condition or syndrome (no ...
) is the initial
patient
A patient is any recipient of health care services that are performed by Health professional, healthcare professionals. The patient is most often Disease, ill or Major trauma, injured and in need of therapy, treatment by a physician, nurse, op ...
in the
population sample of an
epidemiological investigation.
Other fields
The
year zero does not exist in the widely used
Gregorian calendar
The Gregorian calendar is the calendar used in most parts of the world. It went into effect in October 1582 following the papal bull issued by Pope Gregory XIII, which introduced it as a modification of, and replacement for, the Julian cale ...
or in its predecessor, the
Julian calendar
The Julian calendar is a solar calendar of 365 days in every year with an additional leap day every fourth year (without exception). The Julian calendar is still used as a religious calendar in parts of the Eastern Orthodox Church and in parts ...
. Under those systems, the year
1 BC is followed by
AD 1. However, there is a year zero in
astronomical year numbering (where it coincides with the Julian year 1 BC) and in
ISO 8601:2004 (where it coincides with the Gregorian year 1 BC), as well as in all
Buddhist
Buddhism, also known as Buddhadharma and Dharmavinaya, is an Indian religion and List of philosophies, philosophical tradition based on Pre-sectarian Buddhism, teachings attributed to the Buddha, a wandering teacher who lived in the 6th or ...
and
Hindu calendar
The Hindu calendar, also called Panchangam, Panchanga (), is one of various lunisolar calendars that are traditionally used in the Indian subcontinent and Southeast Asia, with further regional variations for social and Hindu religious purposes ...
s.
In many countries, the
ground floor in buildings is considered as floor number 0 rather than as the "1st floor", the naming convention usually found in the United States of America. This makes a consistent set with underground floors marked with negative numbers.
While the ordinal of 0 mostly finds use in communities directly connected to mathematics, physics, and computer science, there are also instances in classical music. The composer
Anton Bruckner
Joseph Anton Bruckner (; ; 4 September 182411 October 1896) was an Austrian composer and organist best known for his Symphonies by Anton Bruckner, symphonies and sacred music, which includes List of masses by Anton Bruckner, Masses, Te Deum (Br ...
regarded his early ''Symphony in D minor'' to be unworthy of including in the canon of his works, and he wrote ("doesn't count") on the score and a circle with a crossbar, intending it to mean "invalid". But posthumously, this work came to be known as
''Symphony No. 0 in D minor'', even though it was actually written after
''Symphony No. 1 in C minor''. There is an even earlier ''Symphony in F minor'' of Bruckner's, which is sometimes called
''No. 00''. The Russian composer
Alfred Schnittke
Alfred Garrievich Schnittke (24 November 1934 – 3 August 1998) was a Russian composer. Among the most performed and recorded composers of late 20th-century classical music, he is described by musicologist Ivan Moody (composer), Ivan Moody as a ...
also wrote a
Symphony No. 0.
In some universities, including Oxford and Cambridge, "week 0" or occasionally "noughth week" refers to the week before the first week of lectures in a term. In Australia, some universities refer to this as "O week", which serves as a pun on "
orientation week". As a parallel, the introductory weeks at university educations in
Sweden
Sweden, formally the Kingdom of Sweden, is a Nordic countries, Nordic country located on the Scandinavian Peninsula in Northern Europe. It borders Norway to the west and north, and Finland to the east. At , Sweden is the largest Nordic count ...
are generally called (zeroing).
The
United States Air Force
The United States Air Force (USAF) is the Air force, air service branch of the United States Department of Defense. It is one of the six United States Armed Forces and one of the eight uniformed services of the United States. Tracing its ori ...
starts basic training each Wednesday, and the first week (of eight) is considered to begin with the following Sunday. The four days before that Sunday are often referred to as "zero week".
24-hour clock
The modern 24-hour clock is the convention of timekeeping in which the day runs from midnight to midnight and is divided into 24 hours. This is indicated by the hours (and minutes) passed since midnight, from to , with as an option to indicate ...
s and the international standard
ISO 8601 use 0 to denote the first (zeroth) hour of the day, consistent with using the 0 to denote the first (zeroth) minute of the hour and the first (zeroth) second of the minute. Also, the
12-hour clock
The 12-hour clock is a time convention in which the 24 hours of the day are divided into two periods: a.m. (from Latin , translating to "before midday") and p.m. (from Latin , translating to "after midday"). Each period consists of 12&nb ...
s used in
Japan
Japan is an island country in East Asia. Located in the Pacific Ocean off the northeast coast of the Asia, Asian mainland, it is bordered on the west by the Sea of Japan and extends from the Sea of Okhotsk in the north to the East China Sea ...
use 0 to denote the hour immediately after midnight and noon in contrast to 12 used elsewhere, in order to avoid confusion
whether 12 a.m. and 12 p.m. represent noon or midnight.
Robert Crumb
Robert Dennis Crumb (; born August 30, 1943) is an American artist who often signs his work R. Crumb. His work displays a nostalgia for American folk culture of the late 19th and early 20th centuries, and satire of contemporary American c ...
's drawings for the first issue of ''
Zap Comix
''Zap Comix'' is an underground comix series which was originally part of the Counterculture of the 1960s, counterculture of the late 1960s. While a few small-circulation self-published satirical comic books had been printed prior to this, ''Zap' ...
'' were stolen, so he drew a whole new issue, which was published as issue 1. Later he re-inked his photocopies of the stolen artwork and published it as issue 0.
The
Brussels ring road in Belgium is numbered R0. It was built after the ring road around
Antwerp
Antwerp (; ; ) is a City status in Belgium, city and a Municipalities of Belgium, municipality in the Flemish Region of Belgium. It is the capital and largest city of Antwerp Province, and the third-largest city in Belgium by area at , after ...
, but Brussels (being the capital city) was deemed deserving of a more basic number. Similarly the (unfinished) orbital motorway around
Budapest
Budapest is the Capital city, capital and List of cities and towns of Hungary, most populous city of Hungary. It is the List of cities in the European Union by population within city limits, tenth-largest city in the European Union by popul ...
in Hungary is called
M0.
Zero is sometimes used
in street addresses, especially in schemes where even numbers are one side of the street and odd numbers on the other. A case in point is
Christ Church on
Harvard Square
Harvard Square is a triangular plaza at the intersection of Massachusetts Avenue (Boston), Massachusetts Avenue, Brattle Street (Cambridge, Massachusetts), Brattle Street and John F. Kennedy Street near the center of Cambridge, Massachusetts, C ...
, whose address is 0 Garden Street.
Formerly in
Formula One
Formula One (F1) is the highest class of worldwide racing for open-wheel single-seater formula Auto racing, racing cars sanctioned by the Fédération Internationale de l'Automobile (FIA). The FIA Formula One World Championship has been one ...
, when a defending world champion did not compete in the following season, the number 1 was not assigned to any driver, but one driver of the world champion team would carry the number 0, and the other, number 2. This did happen both in 1993 and 1994 with
Damon Hill carrying the number 0 in both seasons, as defending champion
Nigel Mansell quit after 1992, and defending champion
Alain Prost quit after 1993. However, in 2014 the series moved to drivers carrying career-long personalised numbers, instead of team-allocated numbers, other than the defending champion still having the option to carry number 1. Therefore 0 is no longer used in this scenario. It is not clear if it is available as a driver's chosen number, or whether they must be between 2 and 99, but it has not been used to date under this system.
Some team sports allow 0 to be chosen as a player's
uniform number (in addition to the typical range of 1-99). The NFL voted to allow this from 2023 onwards.
A chronological prequel of a series may be numbered as 0, such as ''
Ring 0: Birthday'' or ''
Zork Zero''.
The
Swiss Federal Railways
Swiss Federal Railways (, SBB; , CFF; , FFS) is the national railway company of Switzerland.
The company was founded in 1902 and is headquartered in Bern. It used to be a State-owned enterprise, government institution, but since 1999 it has be ...
number certain classes of rolling stock from zero, for example,
Re 460 000 to 118.
In the realm of fiction,
Isaac Asimov
Isaac Asimov ( ; – April 6, 1992) was an Russian-born American writer and professor of biochemistry at Boston University. During his lifetime, Asimov was considered one of the "Big Three" science fiction writers, along with Robert A. H ...
eventually added a Zeroth Law to his
Three Laws of Robotics, essentially making them four laws.
A standard
roulette
Roulette (named after the French language, French word meaning "little wheel") is a casino game which was likely developed from the Italy, Italian game Biribi. In the game, a player may choose to place a bet on a single number, various grouping ...
wheel contains the number 0 as well as 1-36. It appears in green, so is classed as neither a "red" nor "black" number for betting purposes. The card game
Uno has number cards running from 0 to 9 along with special cards, within each coloured suit.
The
Four Essential Freedoms of Free Software are numbered starting from zero. This is for historical reasons: the list originally had only three freedoms, and when the fourth was added it was placed in the zeroth position as it was considered more basic.
See also
*
Zeroth-order approximation
*
Off-by-one error
An off-by-one error or off-by-one bug (known by acronyms OBOE, OBOB, OBO and OB1) is a logic error that involves a number that differs from its intended value by 1. An off-by-one error can sometimes appear in a mathematics, mathematical context. ...
References
Citations
Sources
* This article incorporates material taken fro
zerothat the
Free On-line Dictionary of Computing prior to 1 November 2008 and incorporated under the "relicensing" terms of the
GFDL, version 1.3 or later.
{{refend
Ordinal numbers
0 (number)